开发者

javascript on href disabeld on apps?

Suddenly all my apps does not work the javascript I include in href, sample:

<a hre开发者_如何学Pythonf="javascript:dosomething()">click</a>

this worked ok a week a go but now it does not execute anyway. is there any way to fix this?


you could use onclick instead of href

<a href="javascript:;" onclick="javascript:doSomething();">Click1</a>   
<a href="javascript:void(0);" onclick="javascript:doSomething();">Click2</a>   
<a href="javascript:void(0);" onclick="javascript:doSomething();return false;">Click3</a>   
<a href="#" onclick="javascript:doSomething();">Click4</a>   
<a href="###" onclick="javascript:doSomething();">Click5</a>  


I have seen this issue as well, not sure what is causing it. Because we use ASP.NET link buttons render using the href, and therefore don't post back. Adding the following code turnes an href into an onclick event.

<script type="text/javascript">

__onclick = function() {
  eval(this._js);
}

__evalLinks = function() {
  if (navigator.userAgent.indexOf("Firefox")!=-1) return;

  var oLinks = document.getElementsByTagName("a");
  for (var i=0;i<oLinks.length;i++) {
    if(!oLinks[i].onclick && oLinks[i].href.length > 11 && oLinks[i].href.substr(0, 11) == "javascript:") {
      oLinks[i].onclick = __onclick;
      oLinks[i]._js = unescape(oLinks[i].href.substr(11, oLinks[i].href.length-11));
    }
  }
}

window.onload = __evalLinks;
</script>

Many Thanks, Ady


Try:

<a href="#" onClick="dosomething(); return false;">click</a>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜