#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Posts
    11
    Rep Power
    0

    Can't get Javascript popup URLs to play nice.


    I'm working on a site with a number of popup windows created by image links, and as much as I dislike the concept, the designers simply can't be talked out of using them.

    If I didn't care about people with JavaScript disabled, I'd encode those URLs like so, with the "Popup" function residing in the HTML <head> or a .js file:

    Code:
    <a href="javascript:Popup('mypage.html','mywindow');">
    <img src="myimage.png" height="x" width="x" border="0" alt="image of myimage">
    </a>
    I'd rather be nice, though, so I'd rather not do that. Instead, I'd like to do something like this:

    Code:
    <a href="mypage.html" onclick="Popup('mypage.html','mywindow');">
    <img src="myimage.png" height="x" width="x" border="0" alt="image of myimage">
    </a>
    When I use that code in Netscape 6.2.1 and Opera 6 for Windows, my primary testing browsers, both the popup window and the regular link are followed, resulting in mypage.html being displayed in both a popup window and in the primary window, which really defeats the purpose of using the popup window at all. I just want JavaScript-enabled browsers to do the onclick part, and non-JavaScript-enabled browsers to follow the regular link.

    I worked out this ugly workaround:

    Code:
    <script type="text/JavaScript">
    <!--
    // I know this string shouldn't have these line breaks
    document.write("<a href=\"javascript:Popup('mydocument.html','mywindow');\"\>
    <img src=\"myimage.png\" height=\"x\" width=\"x\" border=\"0\" alt=\"image of myimage\"\>
    </a\>");
    //-->
    </script>
    <noscript>
    <a href="mypage.html">
    <img src="myimage.png" height="x" width="x" border="0" alt="image of myimage">
    </a>
    </noscript>
    That's about the least elegant piece of code I've ever seen (and probably has some problems as it is here, I just wrote it out from memory and I never escape strings properly the first time around. I also had to add some line breaks so we wouldn't all have to scroll to the side just to read this thread).

    So what am I doing wrong with the <a href="..." onclick="..."> bit? How else can I make these image link popups pop up for those with JavaScript and just go to the page itself for those without?

    Thanks a bunch.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    14
    <a href="mypage.html" target="_blank" onclick="Popup('mypage.html','mywindow');return false;">


    [use target="window_name" if you want all the links opened in the same window]
    Last edited by mrrichardfeder; January 24th, 2002 at 08:38 PM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Posts
    11
    Rep Power
    0
    Doh!

    Thanks a lot.

IMN logo majestic logo threadwatch logo seochat tools logo