Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Different link on image depending on browser

    Hello,
    I have an image that is a link and I want the same image to have a different destination when clicked depending on the users browser. If they are using Firefox I want them to go to one specific link and if not I want them to go to another. I was able to do this with a text link, but I can't do it with an image. This is what works for the text with the link text of "TEXT" but how do I replace the link text with an image? What I have so far is:
    <SCRIPT language="JavaScript">
    <!--
    var browserName=navigator.appName;
    var str="TEXT";
    {
    if (browserName=="Netscape")
    {
    document.write(str.link("/one.html"));
    }
    else
    {
    document.write(str.link("two.html"));
    }
    }
    //-->
    </SCRIPT>

    Thank you so much for your help

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    May I ask you why do you need that? Usually the developers try to do a single site/document visible the same in all the browsers.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I agree with Kor, but .....

    Code:
    <script type = "text/javascript">
    
    function redirect() {
    var browserName = navigator.appName; 
    if (browserName == "Netscape"){ 
    window.location = "/one.html";
    }
    else {
    window.location = "/two.html";
    }
    }
    
    </script>
    
    
    <img src = "hog.gif" onclick ="redirect()">
    BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank You For This Post" button.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    When I put that question I thought that, maybe, guru84 need that to make a sort of tutorial in examples how act some browsers in different situations, or something like that. In any other cases detecting the browser by appName is useless, even confusing (for instance some browsers pretend to bear other names - ex: Opera -> IE...).

    There are cases when you need, for a crossbrowser code, to write separate codes for separate browsers, but in fact what is important is not the browser itself (which might behave in different manners, according to the version - ex: IE5 - IE6 - IE7, or NS4 - NS6 - NS7) but the javascript method/object which can be applied.

    By short, don't detect the browser, detect the method/object

    A classical example to refer elements:
    Code:
    if(document.getElementById){//modern browsers; IE5, 6, 7, 8 will enter here
    }
    else if(document.all){//IE4
    }
    else if(document.layers){//NS4
    }
    There are as many crossbrowser codes as differences between methods/objects, not as browsers' type.

    As a note, Netscape is almost dead and buried. I see no use in detecting it. Even so, which Netscape? 4, 6, 7, 8?

    What is so special in your page that you need a duplicate for Netscape only?
    Last edited by Kor; 04-26-2008 at 09:22 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Obviously the flow of this thread depends on the next post of guru84, but if he really want to proceed with this idea, then a serverside sniffing would be more practical, assuming he has some serverside script support.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    For some unfathomable reason the OP wants to detect the browser. If the browser is Netscape he wishes to redirect to a certain page, if not (default) to another page.

    Perhaps he wants to show a message saying "Netscape is now virtually obsolete - get yourself MSIE 7" or something.

    The deprecated <SCRIPT language="JavaScript"> gives a clue.

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by Philip M View Post
    For some unfathomable reason the OP wants to detect the browser.
    I doubt about it. Most of the unexperienced coders only think that they need to detect the browser to redirect the location, because they have no idea that they might detect the method instead, or even make a single crossbrowser code for a single page. Let's find out the real reason for guru84 has two pages, one for Netscape, one for the others.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #8
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks everyone for your ideas. The reason that I want this is because an advertiser on my site advertises an add-on for Firefox and doesn't want to waste impressions on other browsers. For some reason targeting to Firefox only works when the name "Netscape" is used. Just because thats the way things have worked out I therefore have 2 seperate pages, depending on the visitors browser. I am yet to try the ideas above but I will give them a go and let you know how they work.
    Thanks again.


  •  

    Posting Permissions

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