I. Description
Sometimes IE browsers cannot display some pages, so we need to define different pages for different browser types. How to distinguish the browsers?
We can make the judgement by the user-agent header of the browser, and then use the pop-up box to display the browser type, the effect is as follows:
II. Example
Create a new template, insert a button in cellA1, name it check browser, and add a Click event:
function myBrowser(){
var userAgent = navigator.userAgent; //Get the userAgent string of the browser
var isOpera = userAgent.indexOf("Opera") > -1;
if (isOpera) {
return "Opera"
}; //Determine whether it is Opera browser
if (userAgent.indexOf("Firefox") > -1) {
return "FF";
} //Determine whether it is the Firefox browser
if (userAgent.indexOf("Chrome") > -1){
return "Chrome";
}
if (userAgent.indexOf("Safari") > -1) {
return "Safari";
} //Determine whether it is Safari browser
if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
return "IE";
}; //Determine whether it is IE browser
}
//The following is to call the above function
var mb = myBrowser();
if ("IE" == mb) {
alert("I am IE");
}
if ("FF" == mb) {
alert("I am Firefox");
}
if ("Chrome" == mb) {
alert("I am Chrome");
}
if ("Opera" == mb) {
alert("I am Opera");
}
if ("Safari" == mb) {
alert("I am Safari");
}
Save the template, click Data Entry Preview, and the effect is as shown in the beginning.