Err Posted January 27, 2006 Share Posted January 27, 2006 Hello. I'm new to javascript and I'm in the process of learning more about it. I've found a javascript I want to use it on a web page. This Javascript detects any other browser version that is not IE, and tells the user that. Here is the code: <script type="text/javascript">if (navigator.userAgent.indexOf("Firefox")!=-1)alert("Firefox user, you need Internet Explorer to view this page correctly!");</script> However, I want to add an OK and Cancel buttons in the alert box (instead of just an OK button). The OK to redirect the user to another page, and the Cancel to close the Alert box... Is this possible? I've been playing with it for a while now, to see if I could do it myself, but I couldn't Can someone please help me. I hope it's not too much to ask.so far I've tried this: <script type="text/javascript"> if (navigator.userAgent.indexOf("Firefox")!=-1){ alert("Firefox user, you need Internet Explorer to view this page correctly!"); window.location="http://www.google.com"} else window.location="http://www.w3schools.com"</script> Link to comment Share on other sites More sharing options...
johnmendel Posted January 27, 2006 Share Posted January 27, 2006 your using too limited of an object <html><head><title>test</title><script>function confirmFF(){ if (confirm("Firefox user, you need Internet Explorer to view this page correctly!")) window.location = "http://www.microsoft.com/windows/ie/"}</script></head><body onLoad="confirmFF();"></body></html> Link to comment Share on other sites More sharing options...
Err Posted January 27, 2006 Author Share Posted January 27, 2006 Well I acomplished the impossible. It took me about 2 hours to figure it out but I did it! (Not too bad for a person that hasn't taken a single Javascript class).Thanks johnmendel for that bit of help. But I don't like the 'function' keyword because I'll have to add it to an object to activate that javascript. I'm still curious with your message. What do you mean that I'm using a limited object? Am I not using right javascript? :S <script type="text/javascript"> if (navigator.userAgent.indexOf("Firefox")!=-1 && (confirm ("Firefox user, you need Internet Explorer to view this page correctly! \n \n Click OK to download it, otherwise click Cancel to continue.")) ) window.location="http://www.microsoft.com/"</script> Link to comment Share on other sites More sharing options...
johnmendel Posted January 27, 2006 Share Posted January 27, 2006 I meant that an alert box is limited in what it can do. aka the comment box was what you needed. Link to comment Share on other sites More sharing options...
Err Posted January 27, 2006 Author Share Posted January 27, 2006 I See what you mean, that Confirm box helped out.I got it to do extactly what I wanted it to do, but I've come across yet another problem. I had serveral lines of Javascript code in the original Javascript that I was using (For the different types of browsers). Now I can't get the code to work whenever I add it back to the original. Once again, I edited the other Javascript codes so users of different browsers can get the same message as in the firefox one. However whenever I add it back into the code, the javascript completly stops working. I know there has to be a work around for this, I'm not advanced enough in this language to fully understand what is going on.The below code is the FULL javascript that I want to use. May I add that I want all this code to be under one javascript tag, not serveral. if (navigator.userAgent.indexOf("Firefox")!=-1 && (confirm ("Firefox user, you need Internet Explorer to view this page correctly! \n \n Click OK to download it, otherwise click Cancel to continue.")) )window.location="http://www.microsoft.com/"if(navigator.appName == "WebTV") && (confirm ("WebTV user, you need Internet Explorer to view this page correctly! \n \n Click OK to download it, otherwise click Cancel to continue.")) )window.location="http://www.microsoft.com/"if (navigator.userAgent.indexOf("Netscape")!=-1) && (confirm ("Netscape user, you need Internet Explorer to view this page correctly! \n \n Click OK to download it, otherwise click Cancel to continue.")) )window.location="http://www.microsoft.com/"if (navigator.userAgent.indexOf("Opera")!=-1) && (confirm ("Opera user, you need Internet Explorer to view this page correctly! \n \n Click OK to download it, otherwise click Cancel to continue.")) )window.location="http://www.microsoft.com/" If someone can PLEASE help me put this code together somehow so it can work on those selected browsers. I would REALLY appreciate it! Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now