JS detects if the client browser is a 360 browser method

Source: Internet
Author: User

Since the 3Q War 360 browser useragent has become ie, the common method of judgment is also ineffective, so have to change the way.

On page 360, press F12, pull up the debugging window, analyze the Navigator and window two objects, and finally find a value that can be used to identify 360 browsers.

<script>
if (Window.external&&window.external.twgetrunpath&&window.external.twgetrunpath (). ToLowerCase () . IndexOf ("360SE") >-1) {alert (' This site does not support 360 browser access, please change other browsers! ") ');} Else{alert (' non 360 ');}
</script>

The test results let us down.


Keep looking (The following code is available in the 360 security browsers 5 and 6 versions)

)

<script>
var check360browser={
If it's 360 browsers,
"OK": function () {
Here's the code after the 360 success.
Alert (' JS-> 360 ');
},
' TRY360SE ': function (callback) {
var ret = False,
img = new Image ();
IMG.SRC = ' res://360se.exe/2/2025 ';
Img.onload = function () {
ret = true;
}
settimeout (function () {
if (ret==true) {
Check360browser.ok ();
}else{
Ret=check360browser.try360se_2 ();
if (ret) {
Check360browser.ok ();
}
}
}, 100);
},
' Try360se_2 ': function () {
var is360 = false;
if (window.navigator.userAgent.indexOf (' Chrome ')!=-1) {
if (window.navigator.webkitPersistentStorage) {

}else{
return true;
}
}
}
}
CHECK360BROWSER.TRY360SE ();
</script>

Window.navigator members of the collection, think that should be so many members of the collection, 360 will not be achieved? The result finally found some differences, the following gives my judgment code.

<%@ page language= "java" import= "java.util.*" pageencoding= "GBK"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<base >

<title></title>

<script>
function bro () {
var is360 = false;
var Isie = false;
if (Window.navigator.appName.indexOf ("Microsoft")!=-1) {
Isie= true;
}
if (isie&& (window.navigator.userprofile+ ') = = ' null ') {
Is360 = true;
}
if (is360) {
Document.body.innerText = ' 360 browser ';
}else if (Isie) {
Document.body.innerText = ' IE browser ';
}
}
</script>

<body onload= "bro ();" >

</body>

Be careful not to forget this sentence, or you will not be able to implement the results.

[HTML] View plaincopy on code to see a snippet derived from my Code slice

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

I have used the above method in the project, the effect is OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.