Jump to content

JavaScript Ok & Cancel Box


Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...