Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 32
Location: Indiana, USA
Trades: 0
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!
 
 
Register now for full access!
Old 06-24-2006, 07:53 PM Re: Browser detect with alert not working
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Opera by default identifies itself as Internet Explorer (MSIE 6.0)

Tools -> Preferences -> Network -> Browser Identification
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-25-2006, 12:41 AM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
Trades: 0
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, 05:51 AM Re: Browser detect with alert not working
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
it's a possibility
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-25-2006, 10:15 AM Re: Browser detect with alert not working
Extreme Talker

Posts: 160
Trades: 0
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 10:17 AM..
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 06-25-2006, 11:26 AM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
Trades: 0
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, 03:48 PM Re: Browser detect with alert not working
Extreme Talker

Posts: 160
Trades: 0
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, 09:19 PM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
Trades: 0
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, 10:02 PM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
Trades: 0
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, 05:57 AM Re: Browser detect with alert not working
Extreme Talker

Posts: 160
Trades: 0
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, 06:56 PM Re: Browser detect with alert not working
Experienced Talker

Posts: 32
Location: Indiana, USA
Trades: 0
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, 08:57 PM Re: Browser detect with alert not working
Junior Talker

Posts: 1
Name: Lionel
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.41491 seconds with 12 queries