I've seen a lot of browser redirect scripts but I haven't seen one that redirects to Opera...can somebody post one?
I've seen a lot of browser redirect scripts but I haven't seen one that redirects to Opera...can somebody post one?
<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.
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
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.
window.opera will do the job:Originally Posted by edman
Code:if(window.opera){ ... }
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.
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>
onload=objDetection;
That doesn't need to be in the body tag?
Nice
Very good script from the looks of it.
You don't really need an onload function or all those brackets (red):
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:<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>
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.Code:var ie5 = (document.all && document.getElementById && !window.opera);
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
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.Originally Posted by edman
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.
Netscape 4, Escape, and OmniWeb.Originally Posted by otaku
Netscape 6, iConnector, NetBox, Operas 5 & 6 (when not spoofing IE), Mozilla, K-meleon, Gostzilla, Doczilla, Firefox and other Gecko based browsers.var ns6 = (!document.all && document.getElementById);
Internet Explorer 4 and OmniWeb.var ie4 = (document.all && !document.getElementById);
Internet Explorer 5+, Konquerer, Safari, NetFront, Web Browser, iCab, and IceBrowser.var ie5 = (document.all && document.getElementById && !window.opera);
That is not an exhaustive list.
Utter junk, as usual.
Mike
Bookmarks