if(navigator.appName.indexOf(“Explorer”) > -1)
var text = document.getElementById(“text”).innerText;
else
var text = document.getElementById(“text”).textContent;
用来获取浏览器的名称,第一句话的意思就是当获取到的浏览器的名称中带有Explorer。
涉及到indexof用法
strObj.indexOf(subString[, startIndex])
参数
strObj
必选项。String 对象或文字。
subString
必选项。要在 String 对象中查找的子字符串。
starIndex
可选项。该整数值指出在 String 对象内开始查找的索引。如果省略,则从字符串的开始处查找。
indexOf 方法返回一个整数值,指出 String 对象内子字符串的开始位置。如果没有找到子字符串,则返回 -1。