I have some problem with my javascript
functions. I want to add some parameters to the href
url when it cliked. For example I want to add ?param=1
in href
url when it's clicked. But before add some parameters I want to check if the url in href
is http://example.com and that parameters not contain ?param=1
. After it checked and the url is http://example.com and not contain ?param=1
, I want to add the ?param=1
in that url. Why I want to check first before adding the parameters? It's because I don't want to add the parameters in any url but just in specific url which I want.
This is what I do till now:
window.addEventListener("click", function(e) {
var href = e.target.getAttribute("href");
if(href) {
location.href = href + "?param=1";
e.preventDefault();
}
});
But, I don't know how to check and make specific conditions if the href
is http://example.com. Please anybody know how to do this could help me. Thanks before.