Reply
Browser detect with alert not working
Old 06-24-2006, 05:54 PM Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
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:

Code:
<script type="text/javascript">

var browser = navigator.appName

if (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?
__________________
They have computers, and they may have other weapons of mass destruction. - - Janet Reno
Smoking Man is offline
Reply With Quote
View Public Profile Visit Smoking Man's homepage!
 
When You Register, These Ads Go Away!
Old 06-24-2006, 06:53 PM Re: Browser detect with alert not working
chrishirst's Avatar
Super Moderator

Posts: 13,609
Location: Blackpool. UK
Opera by default identifies itself as Internet Explorer (MSIE 6.0)

Tools -> Preferences -> Network -> Browser Identification
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-24-2006, 11:41 PM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
Quote:
Originally Posted by chrishirst
Opera by default identifies itself as Internet Explorer (MSIE 6.0)

Tools -> Preferences -> Network -> Browser Identification
So what you're saying is that my cleverly thought out solution isn't going to work?

__________________
They have computers, and they may have other weapons of mass destruction. - - Janet Reno
Smoking Man is offline
Reply With Quote
View Public Profile Visit Smoking Man's homepage!
 
Old 06-25-2006, 04:51 AM Re: Browser detect with alert not working
chrishirst's Avatar
Super Moderator

Posts: 13,609
Location: Blackpool. UK
it's a possibility
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-25-2006, 09:15 AM Re: Browser detect with alert not working
Extreme Talker

Posts: 158
The following should detect Opera even when its spoofing, however, I would try to get your slideshow to work in Opera rather than deny users access to the feature.

Code:
<script type="text/javascript">

var browser = navigator.userAgent;

if (browser.indexOf("Opera") != -1)    {
    alert("Your browser will not execute the slideshow script" + '\n' + "It must be viewed in either Internet Explorer or Firefox")
    }
</script>

Last edited by ElectricSheep : 06-25-2006 at 09:17 AM.
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 06-25-2006, 10:26 AM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
Quote:
Originally Posted by ElectricSheep
The following should detect Opera even when its spoofing, however, I would try to get your slideshow to work in Opera rather than deny users access to the feature.
I have tried to get it to work. I'm still learning JS so when I ran the debugger, I didn't completely understand what the problem was, and I wasn't able to get any input from anyone as to where the code needs fixed. I would like to be able to let Opera users see the show.

Here's the link to the original thread:
http://www.webmaster-talk.com/javasc...-in-opera.html

I'll take any help I can get.
__________________
They have computers, and they may have other weapons of mass destruction. - - Janet Reno
Smoking Man is offline
Reply With Quote
View Public Profile Visit Smoking Man's homepage!
 
Old 06-25-2006, 02:48 PM Re: Browser detect with alert not working
Extreme Talker

Posts: 158
Hi again,
The reason you are having an error is because only IE understands transitions.

The problem is IE is not the only browser to understand document.all - Opera does too.
So when Opera satisfies your "document.all" condition it tries to run the transition but fails because it does no support them.

To fix the problem just check for Opera in your conditions :

Code:
if (document.all && navigator.userAgent.indexOf("Opera")==-1)
{
 --- your code ---
}
Opera will run the slideshow but will no longer flag up an error.

HTH
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 06-25-2006, 08:19 PM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
I had tried commenting out the transition code, but it still would not run. Do I need to test for Opera, and then either run the current code or modified code depending on the conditional result?
__________________
They have computers, and they may have other weapons of mass destruction. - - Janet Reno
Smoking Man is offline
Reply With Quote
View Public Profile Visit Smoking Man's homepage!
 
Old 06-25-2006, 09:02 PM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
I tried modifying the code to test for Opera and then run accordingly, but the show still does not run. Here's the modified code, what am I missing here?

Code:
function runSlideShow()    {
    if (document.all && navigator.userAgent.indexOf("Opera") ==-1)    {
        document.images.SlideShow.src = preLoad[j].src;
        
    }else{

    if (document.all)    {
            document.images.SlideShow.style.filter="blendTrans(duration=2)"
            document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
            document.images.SlideShow.filters.blendTrans.Apply()      
        }
    document.images.SlideShow.src = preLoad[j].src
        if (document.all){
            document.images.SlideShow.filters.blendTrans.Play()
        }
    j = j + 1
    //  replace the next line of code with the following commented out line of code to loop slideshow
    //  commented out code  ---  if (j > (p - 1)) j=0   
    
    if (j <=(p-1))
          t = setTimeout('runSlideShow()', slideShowSpeed)
    }
I've left out the arrays and <script> tags. Here's the link to the source:
http://testdomain.ftwin.com/albums/m...slideshow.html
__________________
They have computers, and they may have other weapons of mass destruction. - - Janet Reno
Smoking Man is offline
Reply With Quote
View Public Profile Visit Smoking Man's homepage!
 
Old 06-26-2006, 04:57 AM Re: Browser detect with alert not working
Extreme Talker

Posts: 158
Wherever if(document.all) appears replace it with :

if (document.all && navigator.userAgent.indexOf("Opera")==-1)
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 07-02-2006, 05:56 PM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
Sorry it took so long for me to try this. I only have limited time on the weekends now to work on this. But...I changed all of the occurances of "if(document.all)" to "if(document.all && navigator.userAgent.indexOf("Opera")==-1)" and it still isn't working. I'm trying to view it in Opera v9. Any other suggestions?
__________________
They have computers, and they may have other weapons of mass destruction. - - Janet Reno
Smoking Man is offline
Reply With Quote
View Public Profile Visit Smoking Man's homepage!
 
Old 08-01-2006, 07:57 PM Re: Browser detect with alert not working
Junior Talker

Posts: 1
Name: Lionel
Dear Smoking Man,

I found out how to simply detect Opera the other day. Here is a script for you to try:

<script language="javascript" type="text/javascript">
<!--
if (window.opera) {
alert("Your browser will not execute the slideshow script" + '\n' + "It must be viewed in either Internet Explorer or Firefox");
}
//-->
</script>
lyonlyke is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Browser detect with alert not working
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16203 seconds with 12 queries