Home > OS >  HTML link - href if javascript is disabled, onclick if js is enabled
HTML link - href if javascript is disabled, onclick if js is enabled

Time:07-09

To send users to different links, I use a JS function that when called, creates an animation, times out for a bit and then location.href the user, the problem is that if a user does not have JS enabled, he will not be redirected to the site. Is there any way onclick wold redirect the user normally if he does not have JS enabled and redirect it with my function if JS is enabled?

Thanks is advance!

CodePudding user response:

You could try creating the element with both href and onclick attributes. Then, in your JS, set the href attribute to "javascript:void(0)".

Code would look something like this:

html

<a id="jsElement" href="/newPage.html" onclick="callFunction()">Text</a>

javascript

window.onload = function() {
    document.getElementById("jsElement").setAttribute("href", "javascript:void(0)");
}
  • Related