开发者

How to change link if JS is disable and enable?

开发者 https://www.devze.com 2022-12-30 23:53 出处:网络
I need if JS is enabled then this link will be this <a href=\"#\" class=\"collops\">see sitemap</a>

I need if JS is enabled then this link will be this

<a href="#" class="collops">see sitemap</a>

And is js is disabled then link shou开发者_如何转开发ld be this

<a href="http://stackoverflow.com" class="collops">see sitemap</a>


You do not need to do such things. Just have the onclick function return false, like this:

<a href="http://stackoverflow.com/" onclick="redirect(this.href); return false;">link</a>


Use a function that runs when your page loads to re-write all of your links (or all selected links). That way page renders with proper anchor tags if JS is off, and if it's on they all get replaced to what you need them to be.

Something along the lines of:

$(document).ready(function(){
    $(".collops").attr("href", "#");
});
0

精彩评论

暂无评论...
验证码 换一张
取 消