The “onclick event-handler return false” bug as described in this article does not show up in Internet Explorer 7 when ones uses the DOM scripting library jquery.
If we have anchor elements on a web page and we wish to open in a new window (always the same one) any document these elements link to, then we write the following jquery code :
$(document).ready(function() { $('a').click(function() { window.open($(this).attr('href'), 'new_window'); return false; }); });
Just like we expect it, the return false statement does cancel the default action of the browser for the anchor element.
Attachment | Size | Hits | Last download |
---|---|---|---|
IE7BugOnclickEventHandlerWithJQuery.zip | 747 bytes | 11 | 13 years 21 weeks ago |
Comments
"About"
Hi
I have bug with IE7.
My problem is IE7 insert the word "about" in the middle of my domain http://localhostabout/. Works fine in FF. Crazy Bug!! You have a idea how can I fix it?
I tried insert onclick event like a attribute into my .class but still have same strange behavior.
Regards
Mario
Fixed with last JQuery
Fixed with last JQuery Version
http://jquery.com/blog/2007/02/27/jquery-112/
Bug Fixes
The most important bug fixes, relevant to this release, are as follows:
1. Change: Event handlers (like element.onclick) are now removed when no more functions are bound to the event.
....
Thanks
Passing arguments
I've stumbled across this thread whilst trying to solve an identical problem. Please bear with me. I'm a relative newcomer to JS, and am just getting started with jQuery.
In my case it's an "image picker" for a WYSIWYG editor (vBulletin's). Basically a popup window, a grid of thumbnails, when you select one it inserts bbcode into an editor object to show the thumb as a Lightbox link.
Anyway ... point being I was doing this by passing arguments (thumbnail id, editor id) into a JS function from an href="#" onclick which returned false. Can't do that no mo' in IE, apparently!
I use jQuery in the same popup, for handling the Ajax to do next/prev page of thumbnails. So this thread seems perfect.
My question is, how do I do the passing of the arguments, doing this thru a document ready function? The original example above is obviosuly 'generic', and doesn't use arguments. But if I'm not mistaken, Mario's code above is doing something like I need.
If I read the jQuery correctly (which is unlikely!), it's taking the value of .slideshowCaption and adding it to the URL somehow. I'm not sure (well, haven't a clue to be honest) what the clone stuff does!
Here's what I was doing (taken from the PHP, hence the escaped quotes and $variables, and with some added linebreaks for readability):
If someone could give me a push in the right direction as to how to redo this for $(document).ready use, I would be eternally grateful!
— hugh
Thinking out loud
I know I shouldn't reply to myself, but ...
On closer inspection of Mario's code, he's actually taking the href attribute from an 'a' element whose id is slideshowCaption, appending it to the URL for window.open (with the _self post-pended).
And (I think) then cloning that href attribute and emptying it. Which I presume is what prevents IE from then following the link, 'cos the link isn't there any more. I'm still hazy on the clone() part though!
So I guess this is pretty much exactly what I need to do. Only instead of window.open, I need to call my own function.
I'll no doubt be back, LOL!
-- hugh
Using the rel attribute
Here is what I did using the REL attribute because XHTML strict does not use target=_blank
Hope this helps someone.
c
The “onclick event-handler
The “onclick event-handler return false” bug as described in this article does not show up in Internet Explorer 7 when ones uses the DOM scripting library jquery.
e-papierosy
e-papierosy
e-papierosy
e-papierosy
If we have anchor elements on a web page and we wish to open in a new window (always the same one) any document these elements link to, then we write the following jquery code :
http://twinfountainsec-woodlands.com
no problem Hedges Park Condo, Topiary EC, Twin Fountains Woodlands