从网站特定的浏览器禁用内JS [英] Disabling JS from within Website for specific browsers

查看:154
本文介绍了从网站特定的浏览器禁用内JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站是完全旨在没有的JavaScript。 JS加完全不侵入。

My Website is completely designed to without javascript. JS is added completely non intrusively.

现在我并不想测试JS在所有浏览器(尤其是老年的IE版本),因为他们给了调试没有反馈,它只是不值得我的时间。

Now I don't want to test the JS on all browsers (notably older IE versions), because they give no feedback for debugging, and it's just not worth my time.

所以我只是想在某些浏览器禁用JS(或者相反:允许它在我与测试它的浏览器)。

So I'd simply like to disable JS on some browsers (or the opposite: allow it on the browsers I have tested it with).

有没有办法做到这一点?还是我必须建立一个JS标志,我有我之前执行JS每次咨询? (真的不希望这样做)

Is there a way to do that? Or do I have to create a JS flag that I have to consult every time before I execute JS? (really don't want to do that)

推荐答案

Cwallenpoole的解决方案看起来对我来说,这是行不通的,除非它被称为在DOM ready事件或者至少其他脚本标记后,在这一点上的脚本会已经运行。

Cwallenpoole's solution looks to me like it wouldn't work unless it's called on the DOM ready event or at least after the other script tags, at which point scripts would have already run.

如果所有的脚本都在一个地方,或者至少不是全部嵌入到页面上,也许你应该包括他们使用JavaScript检查浏览器之后:

If all your scripts are in one place, or at least not embedded all over the page, perhaps you should include them with JavaScript after checking the browser:

<script>
    if( /* Browser checks */ )
        document.write( '<script src="scripts.js"></script>' );
</script>

这是说明了为什么让你的code DRY 和所有一个场景在一个地方是非常重要的。

This is one scenario which illustrates why keeping your code D.R.Y. and all in one place is important.

有关检测浏览器,请怪异模式,但要注意的链接到他们的目标检测页面,而不是如果这是为您的使用情况更加有用。 Yepnope.js 是后者有用,这就是Modernizr的一部分。

For detecting browsers, check out quirksmode, but note the link to their Object detection page instead if that's more useful for your use case. Yepnope.js is useful for the latter, which is part of Modernizr.

这篇关于从网站特定的浏览器禁用内JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆