Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: Redirect to Opera script?

  1. #1
    Join Date
    May 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Redirect to Opera script?

    I've seen a lot of browser redirect scripts but I haven't seen one that redirects to Opera...can somebody post one?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    <html>
    <head>
    ...
    <meta http-equiv="refresh" content="5;url=http://google.com">
    ...
    </head>
    <body>...</body></html>


    The 5 means 5 seconds... use what you want, 0 for immediate.
    The ;url= part is optional. note that it doesn't require quotes around the url itself, but only the content="" value as a whole.

  3. #3
    Join Date
    May 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanx, that script will come in handy. But that isn't quite what I meant. I meant, say you create a webpage and you have three different pages, one for IE, one for Firefox, and one for Opera, and you want your index.html file to be a script that will determine what browser the user is using so that you can direct him/her to the either the IE, Firefox, or Opera page. Something like this:
    if(navigator.userAgent.indexOf("Firefox") != -1)
    {
    window.location = "index2.htm";
    }
    else if(navigator.userAgent.indexOf("MSIE") != -1)
    {
    window.location = "index1.htm";
    }

    But how do you write Opera? Will this work...

    else if(navigator.userAgent.indexOf("Opera") != -1)
    {
    window.location = "index3.htm";
    }


    ?????????

    Thanx,
    Edman

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Oh. Right.

    Hmm... not really sure. For IE, there are weird comment-based if statements you can use.

    Something like:
    <!-- [IF IE] <a href="blah.htm">click</a> ELSE --> <a href....></a> <!--....


    Or, just plain JS.

    But i'm not sure how to do that with JS.

    I think that "if document.all" checks, because only IE has that compatibility.

    But... not sure about mozilla vs. opera, etc.


    There are ways, I'm sure.

    But can't really help you.

    Random note-- there's a way to check with PHP what the browser is (more compatible/more complex than JS) and then you could use that. JS might suit your needs, though.

  5. #5
    Join Date
    Apr 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by edman
    I've seen a lot of browser redirect scripts but I haven't seen one that redirects to Opera...can somebody post one?
    window.opera will do the job:
    Code:
    if(window.opera){
    ...
    }

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm... maybe. Does that work for all browsers?
    I wouldn't think it's that simple, but I don't know. Kinda seems familiar, though.

  7. #7
    Join Date
    Apr 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    My suggestion is to use object detection like below:

    Code:
    <script type="text/javascript">
    
    var ns4 = (document.layers);
    var ns6 = (!document.all && document.getElementById);
    var ie4 = (document.all && !document.getElementById);
    var ie5 = (document.all && document.getElementById && !window.opera);
    var op6 = (window.opera && document.getElementById);
    
    function objDetection(){
    	if(ns4){ 
    		alert('Netscape 4');
    	} 
    	if(ns6){ 
    		alert('Mozilla / Firefox / Netscape 6 and more');
    	} 
    	if(ie4){ 
    		alert('Explorer 4');
    	} 
    	if(ie5){ 
    		alert('Explorer 5 and more');
    	}
    	if(op6){ 
    		alert('Opera 6 and more');
    	} 
    } 
    onload=objDetection;
    
    </script>

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    onload=objDetection;

    That doesn't need to be in the body tag?
    Nice

    Very good script from the looks of it.

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You don't really need an onload function or all those brackets (red):

    Code:
    <script type="text/javascript">
    
    var ns4 = (document.layers);
    var ns6 = (!document.all && document.getElementById);
    var ie4 = (document.all && !document.getElementById);
    var ie5 = (document.all && document.getElementById && !window.opera);
    var op6 = (window.opera && document.getElementById);
    
    
    if(ns4){ 
    alert('Netscape 4');
    }
    if(ns6){ 
    alert('Mozilla / Firefox / Netscape 6 and more');
    }
    if(ie4){ 
    alert('Explorer 4');
    }
    if(ie5){ 
    alert('Explorer 5 and more');
    }
    if(op6){ 
    alert('Opera 6 and more');
    }
    
    
    </script>
    But, the brackets would come in handy if you wanted to do more than one thing in each instance. Onload would also be good if you wanted to act upon the loaded document instead of merely fire an alert. You are still treading on dangerous ground here. Not you personally, otaku but, the OP. You are better off designing your page to work in all your target browsers rather than branch off to separate pages. The way the above code equates object detection with certain browsers is accurate but, it is better to write one page with one script that uses object detection when and only when the script needs to use the object. That way any browser that supports the object can use it. We really don't need to know what browser the user has, just whether or not it supports the code. Another way of looking at this is, just because a browser passes this test:

    Code:
    var ie5 = (document.all && document.getElementById && !window.opera);
    is no guarantee that it is IE5+. It may do/be all those things yet not support object.filters. IE5 itself is very limited in its support of that object while IE5.5+'s support for it is quite robust and IE6's even more so. This is just one example of why the object or method you want to use should be tested at the time you use it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by edman
    I meant, say you create a webpage and you have three different pages, one for IE, one for Firefox, and one for Opera [...]
    You would be insane. Not only is browser detection flawed and unreliable (despite claims to the contrary), authoring multiple versions of a document for different user agents is a complete waste of effort.

    If you are having trouble with how a document is rendered, your implementation is broken. Trying to serve different versions of it is not the way forward. You should be attempting to determine why it happens and fix the problem, not avoid it.


    Quote Originally Posted by otaku
    var ns4 = (document.layers);
    Netscape 4, Escape, and OmniWeb.

    var ns6 = (!document.all && document.getElementById);
    Netscape 6, iConnector, NetBox, Operas 5 & 6 (when not spoofing IE), Mozilla, K-meleon, Gostzilla, Doczilla, Firefox and other Gecko based browsers.

    var ie4 = (document.all && !document.getElementById);
    Internet Explorer 4 and OmniWeb.

    var ie5 = (document.all && document.getElementById && !window.opera);
    Internet Explorer 5+, Konquerer, Safari, NetFront, Web Browser, iCab, and IceBrowser.

    That is not an exhaustive list.

    Utter junk, as usual.

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •