/    Sign up×
Community /Pin to ProfileBookmark

How to block all other browsers except chrome?!

Hello,

i want to know, how can i block all other browsers on my website except chrome users? I would like to allow just chrome browser users, all other users i would like to redirect to some example link. I think it can be done with javascript, so please provide me some code example, so i can use it on my website.

Thanks

to post a comment
JavaScript

14 Comments(s)

Copy linkTweet thisAlerts:
@iBeZiFeb 23.2014 — You could check the user agent to work out which browsers being used, but it isn't 100% reliable.

[code=php]
var chrome = /chrome/i.test(navigator.userAgent);
if(!chrome) {
//user probably isn't using chrome
}
[/code]
Copy linkTweet thisAlerts:
@mbcl63authorFeb 23.2014 — I used your code like this:
[CODE]var chrome = /chrome/i.test(navigator.userAgent);
if(!chrome) {
window.location = "1st-brskalnik.php";
} [/CODE]


And looks like it's working, but is there more reliable way to do it?

Thanks
Copy linkTweet thisAlerts:
@iBeZiFeb 23.2014 — As far as I know checking the user agent is the only way of detecting the browser, it can be spoofed though so people can easily get past the check.
Copy linkTweet thisAlerts:
@Error404Feb 23.2014 — It's recommended in the documentation for the navigator browser object to ideally search for feature detection rather than browser detection depending what it is you want to do. Certain browsers do not return information for navigator.vendor, such as IE, making it a little more browser specific.

[CODE]
<script type = "text/javascript">
if((navigator.vendor.length > 5) && (navigator.vendor.toLowerCase().indexOf("google inc") > -1)) {
window.location.href = "somepage"; // if chrome
} else {
window.location.href = "someotherpage"; // all other browsers
}
</script>
[/CODE]
Copy linkTweet thisAlerts:
@Kevin2Feb 23.2014 — The USER_AGENT can also be checked and acted upon with .htaccess. This method doesn't rely upon someone having JavaScript turned on in their browser. A "belt and suspenders" approach is to use both. But as iBeZi stated, it can still be spoofed.
Copy linkTweet thisAlerts:
@rootFeb 24.2014 — Or you could use PHP

However, you may want to consider that blocking other browsers is a throw back to those users who claim you should get a real web browser and that the person trying to view may not be in a position to install chrome or have the technical ability to do so.

Restricting user access to a single type of browser is a virtual version of cutting your nose off to spite your face.

You should also know that if JavaScript is not present like some browsers out in the WWW do not have javascript or understand javascript (yes they do exist) or even turned off would mean that your blocking script would fail.
Copy linkTweet thisAlerts:
@rootFeb 24.2014 — The USER_AGENT can also be checked and acted upon with .htaccess. This method doesn't rely upon someone having JavaScript turned on in their browser. A "belt and suspenders" approach is to use both. But as iBeZi stated, it can still be spoofed.[/QUOTE]

The term kevin2 is "Belts and Braces" approach.
Copy linkTweet thisAlerts:
@Kevin2Feb 24.2014 — the term kevin2 is "belts and braces" approach.[/quote]
Ha! Good catch! ?
Copy linkTweet thisAlerts:
@Logic_AliFeb 24.2014 — [CODE]<span id='needChrome' style='font-weight:bold; color:red'>This site is intended only for the Google Chrome browser. <a href='notforchrome.com'>Click here.</a></span>

<script type='text/javascript'>

if( !window.chrome )
location.href = 'http://notforchrome.com';
else
document.getElementById( 'needChrome' ).style.display = 'none';

</script>[/CODE]


The PHP [FONT=courier new]get_browser[/FONT] function may have issues: [URL]http://uk1.php.net/get_browser[/URL]
Copy linkTweet thisAlerts:
@mbcl63authorFeb 24.2014 — It's recommended in the documentation for the navigator browser object to ideally search for feature detection rather than browser detection depending what it is you want to do. Certain browsers do not return information for navigator.vendor, such as IE, making it a little more browser specific.

[CODE]
<script type = "text/javascript">
if((navigator.vendor.length > 5) && (navigator.vendor.toLowerCase().indexOf("google inc") > -1)) {
window.location.href = "somepage"; // if chrome
} else {
window.location.href = "someotherpage"; // all other browsers
}
</script>
[/CODE]
[/QUOTE]


Thank you, i like your way. But, can u please edit this code like this: if its chrome just allow access, if its all other browsers then redirect to someotherpage?
Copy linkTweet thisAlerts:
@mbcl63authorFeb 24.2014 — I did it this way:
[CODE]<script type = "text/javascript">
if((navigator.vendor.length > 5) && (navigator.vendor.toLowerCase().indexOf("google inc") > -1)) {

} else {
window.location.href = "1st-brskalnik.php"; // all other browsers
}
</script>[/CODE]


Is this okay?
Copy linkTweet thisAlerts:
@mbcl63authorFeb 24.2014 — I did it this way:
[CODE]<script type = "text/javascript">
if((navigator.vendor.length > 5) && (navigator.vendor.toLowerCase().indexOf("google inc") > -1)) {

} else {
window.location.href = "1st-brskalnik.php"; // all other browsers
}
</script>[/CODE]


Is this okay?
Copy linkTweet thisAlerts:
@Error404Feb 24.2014 — Try the following. I changed .href (for clicking on a link) to .replace which should re-direct. all you have to do is paste in the actual names of the desired websites.

[CODE]
<script type = "text/javascript">
if((navigator.vendor.length > 5) && (navigator.vendor.toLowerCase().indexOf("google inc") > -1)) {
window.location.replace("somepage.html"); // if chrome
} else {
window.location.replace("someotherpage.html)"; // all other browsers
}
</script>
</CODE]

The code you showed will do nothing if the user is using Chrome (i.e. will stay on the current page) but will go to 1st-brskalnik.php if the browser isn't Chrome.
Copy linkTweet thisAlerts:
@rootFeb 24.2014 — Ha! Good catch! ?[/QUOTE]

? although it does sound sexier!
×

Success!

Help @mbcl63 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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