Add parameters to an URL from a just clicked

后端 未结 2 1655

The scenario is a lot of html files with a lot more of links between them. When I call the first one of them (it would be the index), the link pass several parameters throug

2条回答
  •  清歌不尽
    2021-01-05 06:19

    This will append a string to anything containing an href-attribute when being clicked:

    window.addEventListener("click", function(e) {
        var href = e.target.getAttribute("href");
        if(href) {
            location.href = href + "?q=stackoverflow";
            e.preventDefault();
        }
    });​
    

    Example here: http://jsfiddle.net/E5Q7P/

    Won't work in < IE9

提交回复
热议问题