Syndicate

Feed

No problem with jquery

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.

AttachmentSizeHitsLast download
IE7BugOnclickEventHandlerWithJQuery.zip747 bytes118 years 23 weeks ago
Last edited by Caroline Schnapp about 9 years ago.

One file is attached to this posting. Login or register to download this file.


Comments

"About"

Hi

I have bug with IE7.

$(document).ready(function() {
  $('.slideshowCaption').click(function() {
    window.open("http://localhost" + ($($("a").contains($(".slideshowCaption").text()).clone().empty()).attr("href")), '_self');
    return false;
  });
});

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):

<a 
    href="#"
    onclick=\"vblogetin_pickattach(
        '{$attach_editorid}',
        '{$imgLinkTiny}',
        '{$imgLinkMedium}',
        '{$urlLink}'
    ); 
    return false;\"
>
    <img
        src=\"{$attach['attachTinyURL']}\" 
        alt=\"\"
        border=\"0\"
    />
</a>

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

$(document).ready(function() {
$('a[rel*=link]').click(function(){  
   window.open(this.href);
   return false;
  });
});

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 :

Commonwealth Towers is also

Commonwealth Towers is also near elite schools such Gan Eng Seng Primary School as well as Anglo Chinese Junior College (ACJC). INSEAD, ISS International School and Crescent Girl’s Chool are also around in the area. commonwealth towers developer

http://www.obatpenurunpanasanak.com/

Growing technology can make people more quickly obtain information, one through website.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <css> <html> <javascript> <mysql> <php> <span> <a> <b> <i> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <sup> <sub> <dd> <del> <blockquote> <img> <q> <p> <div>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <javascript>, <mysql>, <php>, <rails>, <ruby>.

More information about formatting options

CAPTCHA
I have to wonder if you're a human spammer or a machine, or less likely someone who cares to leave his or her thoughts behind.