Jump to content

Alert not working


SmokingMan

Recommended Posts

I have a slideshow script that will not work in Opera, so I thought I'd use a browser detect script to display an alert if the user tries to view the slideshow with Opera. But the alert box does not display and I can't seem to figure out why, so I thought another pair of eyes might help.Here's the script:

<script type="text/javascript">var browser = navigator.appNameif (browser =="Opera")	{	alert("Your browser will not execute the slideshow script" + '\n' "It must be viewed in either Internet Explorer or Firefox")	}</script>

Where have I screwed up? :)

Link to comment
Share on other sites

I fixed the "+" sign, but I found another problem. It seems that you can change the preferences in Opera so it shows as either Mozilla or MSIE. If the user does that, then the conditional test won't work. I guess I'll have to figure out why the script doesn't work in Opera. But in running the debugger, I'm having trouble deciphering it since I'm still very new to JS.

Link to comment
Share on other sites

I found on the XMLDOM tutorial that you can do a test on creating ADO objects."window.ActiveXObject" returns boolean true when the browser is IE (or should be)."(document.implementation && document.implementation.createDocument)" returns true when the browser is Mozilla etc etc.And now comes the coolest part. What if you can test that can it handle it. You can't give support to browser in the "Edit Preferences" section, eh? So:

<script type="text/javascript">var browser = navigator.appNameif (!window.ActiveXObject && !document.implementation && !document.implementation.createDocument){alert("Your browser will not execute the slideshow script" + '\n' "It must be viewed in either Internet Explorer or Firefox")}</script>

Note I'm not 100% sure about does this script work, but I think it should work... expect when Opera can return true in "(document.implementation && document.implementation.createDocument)", that might be a bummer that I'm really afraid of.

Link to comment
Share on other sites

It seems that you can change the preferences in Opera so it shows as either Mozilla or MSIE.  If the user does that, then the conditional test won't work.
That's correct, Opera can identify itself as Mozilla or Internet Explorer.This can trick some scripts but this one works fine, if you find the browser through the userAgent then it correctly identifys Opera as itself when disguised as another browser :) (i use opera and tried it, it works fine)
<head><script>var agt=navigator.userAgent.toLowerCase();if (agt.indexOf("opera") != -1){alert("using Opera")}</script></head>

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...