使用“扔".停止Safari加载脚本的脚本 [英] Using "throw" script to stop Safari loading a script
本文介绍了使用“扔".停止Safari加载脚本的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要停止safari桌面加载脚本.
Hi i have the need to stop safari desktop from loading a script.
"Throw"
可能是一个选项,但不确定如何定位特定的浏览器.
这样可以正确定位浏览器吗?
"Throw"
may be an option but not sure how to target a specific browser.
would this target the browser correctly?
if ( /^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
???? throw script "<script type="text/javascript">var cbuser = {name: '', email: '', message: ''}, access_token = 'Z2SxfM5dRhhjzKsm3Auhbi4', cburl = '//www.domain.com/';document.write('<script type="text/javascript" src="' + cburl + 'assets/cmodule-chat/js/chatbull-init.js"></' + 'script>');</script>
" ????}
以及我如何加载throw和我不希望使用safari的脚本
and how do i load throw and the script i dont want safari to use
谢谢
推荐答案
您可以将 head.js 用于浏览器检测和资源加载.这就是您的情况:
You can use head.js for browser detection and resource loading. Here's what it could look like in your case:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/headjs/1.0.3/head.min.js"></script>
<script type="text/javascript">
if(head.browser.name != "safari") {
head.load("path/to/conditional/file.js", function() {
// File is loaded. Do something with it here
});
}
</script>
如果需要,您当然也可以将其包装在doc.ready函数中.
You could certainly wrap it in a doc.ready function too if you needed.
这篇关于使用“扔".停止Safari加载脚本的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文