admin管理员组文章数量:1315034
Ok, so I'm quite new to jQuery, but found this bizzare problem just now,
If we ignore jQuery for a second and consider this scenario, if I have two links like below both with an href
and both with and onclick
event. The first link will not follow the href
because the onclick
returns false, and the second link will because the onclick
returns true.
<a href="/page.html" onclick="return false;">Dont follow</a>
<a href="/page.html" onclick="return true;">Follow</a>
This works just hunky dory in every browser as it should, the thing is, as soon as I include the jQuery script on the page this stops working in all versions of IE which then always follows the href
whether the onclick
returns false or not. (it continues to work fine in other browsers)
Now if I add an event using jQuery and call .preventDefault()
on the event object instead of doing it the old fashioned way this behaves correctly, and you may say, well just do that then? But I have a site with thousands of lines of code and I am adding jQuery support, I don't want to run the risk that I might miss an already defined html onclick=""
and break the web site.
I cant see why jQuery should prevent perfectly normal JavaScript concepts from working, so is this a jQuery bug or am I missing something?
Ok, so I'm quite new to jQuery, but found this bizzare problem just now,
If we ignore jQuery for a second and consider this scenario, if I have two links like below both with an href
and both with and onclick
event. The first link will not follow the href
because the onclick
returns false, and the second link will because the onclick
returns true.
<a href="/page.html" onclick="return false;">Dont follow</a>
<a href="/page.html" onclick="return true;">Follow</a>
This works just hunky dory in every browser as it should, the thing is, as soon as I include the jQuery script on the page this stops working in all versions of IE which then always follows the href
whether the onclick
returns false or not. (it continues to work fine in other browsers)
Now if I add an event using jQuery and call .preventDefault()
on the event object instead of doing it the old fashioned way this behaves correctly, and you may say, well just do that then? But I have a site with thousands of lines of code and I am adding jQuery support, I don't want to run the risk that I might miss an already defined html onclick=""
and break the web site.
I cant see why jQuery should prevent perfectly normal JavaScript concepts from working, so is this a jQuery bug or am I missing something?
Share Improve this question edited Aug 8, 2022 at 21:35 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Mar 12, 2010 at 21:04 3urdoch3urdoch 7,3428 gold badges44 silver badges59 bronze badges3 Answers
Reset to default 3The most likely cause is that you have a syntax error elsewhere in the page that is preventing javascript from running properly on the page. Turn on script error notifications in your browser to make sure it isn't hiding errors from you.
Try also:
onClick = "event.returnValue = false; return false;"
I corrected your sample code for the second link and tested in IE 8 and it works fine. I'm willing to bet JohnFx is right and you have some other error on your page stopping it from working.
I tested using an included jquery library as well.
Sample:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<body>
<a href="/page.html" onclick="return false;">Dont follow</a>
<a href="/page.html" onclick="return true;">Follow</a>
</body>
</html>
本文标签:
版权声明:本文标题:javascript - Old fashioned html onclick return false doesn't work in IE when jQuery script is included - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741973066a2407955.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论