【发布时间】:2016-07-08 12:51:14
【问题描述】:
我希望在我的页面上嵌入浏览器检测,以便如果浏览器是 Firefox,我会启动不同的 iframe(区别在于 data-src 与 src),如此处所示。有人可以帮我在脚本部分进行哪些更改以使其正常工作吗?
<script>
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
isFF = '<iframe width="806" height="634" frameborder="0" scrolling="0" scrolling="no" horizontalscrolling="no" verticalscrolling="no" **src**="../test.html"></iframe>';
notFF = '<iframe width="806" height="634" frameborder="0" scrolling="0" scrolling="no" horizontalscrolling="no" verticalscrolling="no" **data-src**="../test.html"></iframe>';
if(isFirefox = 'true') {
window.load(isFF);
}else {
window.load(notFF);
}
</script>
【问题讨论】:
-
你如何定义“火狐”?你们包括基于 Palemoon、Thunderbird 和 Gecko 的浏览器吗?如果我下载源代码,修改一点代码并自己编译呢?
-
永远不要进行浏览器嗅探。改用特征检测。
标签: javascript jquery html firefox iframe