SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: jQuery IE issue

  1. #1
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery IE issue

    Code JavaScript:
            if (msg.d.Address != null) {
                var $a = $('<a id="courseDirections">');
                $a.attr('href', 'http://maps.google.com/maps?q=' + msg.d.Address + " " + msg.d.City + " " + msg.d.State + ", " + msg.d.Zip)
                .attr('target', '_blank')
                .html("Click to get directions...");
                $('#courseDirections').html($a);
            }

    This code works in all browsers but IE.
    Simply trying to add a link to a div?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Golgotha View Post
    Code JavaScript:
            if (msg.d.Address != null) {
                var $a = $('<a id="courseDirections">');
                $a.attr('href', 'http://maps.google.com/maps?q=' + msg.d.Address + " " + msg.d.City + " " + msg.d.State + ", " + msg.d.Zip)
                .attr('target', '_blank')
                .html("Click to get directions...");
                $('#courseDirections').html($a);
            }
    Try it this way instead:

    Code JavaScript:
    if (msg.d.Address != null) {
        $('<a>', {
            id: 'courseDirections',
            href: 'http://maps.google.com/maps?q=' + msg.d.Address + " " + msg.d.City + " " + msg.d.State + ", " + msg.d.Zip,
            text: 'Click to get directions...',
            click: function () {
                window.open(this.href);
            }
        }).appendTo('#courseDirections');
        ...
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Paul, hey that code works good, except in IE it opens the href in _self AND _blank?

  5. #5
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just did window.open(this.href); return false; and we're good.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Thank you. The _blank target is not valid when using strict HTML4. it was deprecated from due to scripting being more appropriate for that type of behaviour.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •