/    Sign up×
Community /Pin to ProfileBookmark

Browser Detectino

I wish to check to see if the page is using IE and only IE…if it is not using IE, then I wish to redirect to another page. If the user is using IE, then I wish to load the page as normal.

Anyone have a script for this? lets call teh redirect page [url]http://www.google.com[/url] for now.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@toicontienJan 21.2009 — I highly advise against browser detection. Instead, you should try object detection, or maybe a try-catch block. I'm assuming your page uses ActiveX technology of some sort? Why redirect non Internet Explorer users, and what IE-only technology are you using that cannot be reproduced in any other browser?

I'm not trying to question your tactics, rather I'm just trying to get a grip on the incompatible code. You could put the IE-only code inside a try {} statement, and if the browser encounters an error, the catch (e) {} statement executes:
[CODE]try {
return new ActiveXObject("foo");
} catch (e) {
alert("Your browser is not supported.");
window.location = "http://www.google.com/";
}[/CODE]
Copy linkTweet thisAlerts:
@dzirkelbauthorJan 21.2009 — I am using vbscript for validation and I believe firefox doesn't support vbscript.
Copy linkTweet thisAlerts:
@toicontienJan 21.2009 — Firefox supports JavaScript. I'm not sure why what you cant can't be written in JavaScript. Then you don't need to worry about browser detection. Aside from the programming language, are you trying to do something that can't be done in JavaScript? If not, then we can help convert that to JavaScript.
Copy linkTweet thisAlerts:
@mrhooJan 21.2009 — You'd be better off to redirect the user if your validation runs, not if it doesn't.
Copy linkTweet thisAlerts:
@dzirkelbauthorJan 21.2009 — I just want a browser detection to redirect if it is not IE, just as basic as that. The envirnment is controlled where everyone will be using IE, I just want to cover my basis.

there is so much vbscript that I do not want to take the time to convert it all to javascript.
Copy linkTweet thisAlerts:
@toicontienJan 21.2009 — Ah, Ok. I can see what you are saying. Rewriting a ton of code is not feasible. I still think Object detection is the way to go:
[CODE]function isIE() {
return (window.ActiveXObject && document.selection) ? true : false;
}

if ( !isIE() ) {
window.location = "http://www.google.com/";
}[/CODE]


Or, maybe you could go this route:

[code=html]<script language="vbscript">
Function Validation()
{

}
</script>
<!--[if !IE]-->
<script type="text/javascript">
window.location = "http://www.google.com/";
</script>
<!--[endif]-->[/code]

By using Internet Explorer conditional comments, you can hide a SCRIPT tag from Internet Explorer and show it to all others. I believe the syntax above is correct for the conditional comment. If not, this page can help you out. I would suggest using conditional comments.
Copy linkTweet thisAlerts:
@Declan1991Jan 21.2009 — I'd definitely suggest the conditional comments. Just to hammer home the point, it's a terrible idea normally to simply write code for one browser, but if it's in a controlled environment, it's acceptable.
Copy linkTweet thisAlerts:
@dzirkelbauthorJan 21.2009 — works great toic, thanks!
×

Success!

Help @dzirkelb 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...