PDA

View Full Version : site should be open only in chrome?



vinay8484
03-05-2009, 06:38 AM
HELLO java devlopers
i would like to make code for browser specific.
like my site should be open only in chrome.
:p
pls send this code soon.

codeexploiter
03-05-2009, 12:00 PM
Here is a demo



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Google Chrome Document</title>
<style type="text/css">
</style>
<script type="text/javascript">
(function() {
var chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1
if (!chrome) {
alert('You need chrome to view this site');
document.location.href = "http://www.google.com/chrome";
}
})();
</script>
</head>
<body>
<h1>You are using Google Chrome and can view this page</h1>
<h2>Page content</h2>
</body>
</html>


Try to open the page in any non chrome browser you'll be redirected to the Google Chrome Download page (You can specify any custom page that you want to use at this point, if any). This page will be viewable only on Google Chrome.

Hope this helps.

jscheuer1
03-05-2009, 02:56 PM
This page will be viewable only on Google Chrome.

Ahem, or any browser spoofing Chrome or any browser with javascript disabled.

Twey
03-06-2009, 03:03 AM
(function() {
var chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1
if (!chrome) {
alert('You need chrome to view this site');
document.location.href = "http://www.google.com/chrome";
}
})();

This is all quite redundant: there's no point in the anonymous function because there's no point in the single variable it hides.

if (navigator.userAgent.toLowerCase().indexOf('chrome') === -1) {
alert('You need chrome to view this site');
document.location.href = "http://www.google.com/chrome";
}
Don't mix tabs and spaces: it makes the code display oddly on many systems, and quite difficult to edit (in Firefox, which appears to prefer eight-space-wide tabs, the line starting document.location seems to be indented considerably further than the line above it, despite the fact that they're both meant to be on the same level).


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">Don't limit users to using only Western characters on their pages, especially without noting that you've done so. For compatibility reasons and in deference to the large proportion of Web content that is in the Latin script, UTF-8 should be your default character set.


Ahem, or any browser spoofing Chrome or any browser with javascript disabled.
Or any browser that happens to have the string 'chrome' in its user-agent; since 'chrome' is a browser term for the interface, that's not entirely unlikely (Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009021207 GranParadiso/3.0.6 BetterChrome/0.9.5).

If you're trying to do this in the first place, then you're almost certainly doing it wrong. Is your page perhaps broken in other browsers? If so, I suggest fixing it.

jscheuer1
03-06-2009, 03:21 AM
Yes, chrome is not a unique word in the world of browsers. And many browsers (if not already) will soon be able to spoof GC. I'm also sure that there is probably another property of the navigator object (perhaps the vendor property which is 'Google Inc.' - not too many others would have that) that would be fairly unique to GC.

But browser detection used to allow/disallow site use is so wrong anyway, unless your aim is to create a browser specific site. In which case, find a better detection method, and redirect all non-javascript users to a page that tells them that they need javascript for your 'browser of the month club'.

By the way, if the problem is that you are unable to design for other browsers, take heart. Safari is very similar to GC, so there may at least be one other browser that your site will work in.

Twey
03-06-2009, 03:37 AM
Konqueror and Midori too.