/    Sign up×
Community /Pin to ProfileBookmark

browser redirect

I have a web page that works in all the browsers i’ve tried it with, but doesn’t work quite the same. While I try to find a way to make it work the same in every browser, How can I redirect any user that isn’t using IE?

to post a comment
JavaScript

16 Comments(s)

Copy linkTweet thisAlerts:
@felgallOct 29.2005 — Detecting whether or not someone is using IE is about the hardest thing that can be done in Javascript as many other browsers masquerade as IE in order to get around scripts that use simple tests for IE and assume that the other browsers are not as good (which dates back to the version 5 days when IE still kept up with the standards).

Every browser is going to display the page slightly differently and if someone sets up their own stylesheet then your page will look however they want it to look instead of how you have defined it. You define the page content but your visitors have the final say on the appearance of the page.
Copy linkTweet thisAlerts:
@JPnycOct 30.2005 — You can use if(!window.opera) to be sure it's not Opera, and

var bname=navigator.appName;

if ((bname.indexOf("Netscape")!=-1)||(bname.indexOf("Mozilla")!=-1))

for the netscape/mozilla. I think those are present in the UA string even when cloaked.
Copy linkTweet thisAlerts:
@tabzterOct 30.2005 — wrong way round JPnyc.

It is the [B]navigator.appName[/B] and [B]navigator.appVersion[/B] properties that are changed by browsers to identify them as something else.

Best way is to code for mozilla browsers, forget the rest. Eventually all browsers will adopt mozilla standards anyway as they are w3c compliant. Yess even IE.
Copy linkTweet thisAlerts:
@JPnycOct 30.2005 — Mozilla and Netscape don't have cloaking as a native feature, so you only need worry about Opera, and the test I posted will work even if Opera is cloaked. And I believe "opera" is still present in the UA string even if it's cloaked so you could test for that also.

And coding for any one browser is a bad idea if one wants to work in the web development business.
Copy linkTweet thisAlerts:
@gphOct 30.2005 — How can I redirect any user that isn't using IE?[/QUOTE]

<i>
</i>&lt;script type="text/javascript"&gt;var ie6=0&lt;/script&gt;
&lt;script language="vbscript" type="text/vbs"&gt;
ua=navigator.userAgent
ie6=CInt(Mid(ua,InStr(ua,"MSIE")+5,1))&lt;=6
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
if(!ie6)location.href='standards_compliant.htm'
&lt;/script&gt;


As already stated, it sounds like you're writing for the wrong browser.
Copy linkTweet thisAlerts:
@gphOct 30.2005 — By the way, the above sends IE5 Mac to standards_compliant.htm If you need it to stay on the first page you'll need to check navigator.platform in javascript.
Copy linkTweet thisAlerts:
@JPnycOct 30.2005 — You can't test for the presence of MSIE, even in the UA string. If the browser is cloaked it will be present. You have to test for the absence of the others. For instance, Opera will contain MSIE in the UA string when cloaked as IE, but the string also contains the "Opera" no matter what. But window.opera will also work.
Copy linkTweet thisAlerts:
@gphOct 30.2005 — You can't test for the presence of MSIE, even in the UA string. If the browser is cloaked it will be present.[/QUOTE]
I assume you're referring to my post as it's the only code using UA in this thread?

Using vbs has likely been done before but I just recently thought of it. As I understand it, IEwin is the only browser to date that executes it.
Copy linkTweet thisAlerts:
@JPnycOct 30.2005 — Ok, I see. You would send IE to another page, instead of the other way round. But in that case all you need put in the vbscript is the location redirect, since only IE will respond. That's a novel approach, I like it.
Copy linkTweet thisAlerts:
@gphOct 30.2005 — Ok, I see. You would send IE to another page, instead of the other way round.[/QUOTE]

No, it's kind of messy to read without syntax highlighting. It looks like a tag soup :rolleyes:

<i>
</i>ua=navigator.userAgent
ie6=[COLOR=Blue]CInt[/COLOR]([COLOR=Blue]Mid[/COLOR](ua,[COLOR=Blue]InStr[/COLOR](ua,[COLOR=DarkOliveGreen]"MSIE"[/COLOR])+5,1))&lt;=6
returns true if the version is <= 6



hoping that IE7 will be compliant...
<i>
</i>if(!ie6)location.href='standards_compliant.htm'
redirects anything that isn't IE6 win or less
Copy linkTweet thisAlerts:
@gphOct 30.2005 — wrong way round JPnyc.

It is the [B]navigator.appName[/B] and [B]navigator.appVersion[/B] properties that are changed by browsers to identify them as something else.[/QUOTE]

I disagree. In the order JPnyc wrote it, checking for window.opera then checking navigator properties is the way to go in js.


Best way is to code for mozilla browsers, forget the rest. Eventually all browsers will adopt mozilla standards anyway as they are w3c compliant. Yess even IE.[/QUOTE]
I partially agree. IMO the best way is to code for mozilla browsers without using anything current that might break IE. You [url=http://www.thecounter.com/stats/2005/September/browser.php]unfortunately[/url] still have to check it in IE
Copy linkTweet thisAlerts:
@JPnycOct 30.2005 — Right, I tend to forget about 7 because it's still in beta. I haven't used it yet so I don't know how compliant it is or isn't. And yes, you have to check for opera 1st, or it will pass another test not meant for it, if it's cloaked.
Copy linkTweet thisAlerts:
@gphOct 30.2005 — If you haven't read it, [url=http://www.microsoft.com/downloads/details.aspx?FamilyId=718E9B3A-64FE-4A4C-9DDF-57AF0472EAD2&displaylang=en]this[/url] looks to good to be true ?
Copy linkTweet thisAlerts:
@AmazingAntauthorOct 31.2005 — 
As already stated, it sounds like you're writing for the wrong browser.[/QUOTE]


Well, i wrote the page in question with the ability to use it in any browser, or at least most of them. It's a feedback page that uses forms and the submit button emails the values of the form to me. The only reason i'm having any problem blocking anything other than IE is because when someone with IE clicks submit it just asks if they want to send it. In firefox which i use more often, i found that it shows them the entire contents of the message revealing the scripting on my page that forces their windows version, screen size, etc into the email. I was trying to get those to work because I recently left yahoo Geocities for a different server and liked all the site statistics.
Copy linkTweet thisAlerts:
@gphOct 31.2005 — I see AmazingAnt. I've never got into that so I'm not much help there.

If you want to use vbs, you only need this

<i>
</i>[COLOR=Blue]&lt;script[/COLOR] [COLOR=Red]type=[/COLOR]"text/javascript"&gt;

var ie=0

[COLOR=Blue]&lt;/script&gt;[/COLOR]
[COLOR=Blue]&lt;script[/COLOR] [COLOR=Red]language=[/COLOR]"vbscript" [COLOR=Red]type=[/COLOR]"text/vbs"&gt;

ie=1

[COLOR=Blue]&lt;/script&gt;[/COLOR]
[COLOR=Blue]&lt;script[/COLOR] [COLOR=Red]type=[/COLOR]"text/javascript"&gt;

if(!ie)location.href='page.htm'

[COLOR=Blue]&lt;/script&gt;[/COLOR]
Copy linkTweet thisAlerts:
@AmazingAntauthorNov 01.2005 — Thx gph. i put that inside the head tag on my feedback page and then tryed to open it and it sent me to the other page because i opened it in firefox. i then went to it again in IE and it showed me the page and didn't redirect. That's exactly what I needed, so thx alot for it.
×

Success!

Help @AmazingAnt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...