如何检测JavaScript使用哪个Bootstrap版本? [英] How to detect which Bootstrap version is used from JavaScript?

查看:133
本文介绍了如何检测JavaScript使用哪个Bootstrap版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在查看 CSS &来自Bootstrap的 JavaScript 。没有任何模块化在常见别名下。对于JavaScript,它被注入到jQuery的原型中...

I've been looking at the CSS & JavaScript from Bootstrap 3. Nothing is modularized under a common alias. For the JavaScript, it is injected into jQuery's prototype...

如何能够检测来自第三方的用户网页中包含哪个版本的Bootstrap插件/库观点与JavaScript?

How would it be possible to detect which version of Bootstrap is included in a user's web page from a third party plugin/library point of view with JavaScript?

推荐答案

如果你想抓住 Bootstrap的版本根据其在 CSS 文件中的注释,您可以使用以下代码。它已经过测试,以确保它的工作。

In case you want to grab the Bootstrap's version based on its comments in CSS file, you could use the following code. It's been tested, to make sure it works.

假设 Bootstrap的CSS文件 包含一个显示版本的注释(实际上总是这样):

Assume, that Bootstrap's CSS file contains a comment displaying a version (it always does actually):

/*!
 * Bootstrap v3.0.3 (http://getbootstrap.com)
 * Copyright 2013 Twitter, Inc.
 * Licensed under http://www.apache.org/licenses/LICENSE-2.0
 */

请记住 同源策略 ,当使用 jQuery.get() 方法,其中请求将不会成功执行,如果数据源来自不同的域, ,或协议。

Remember about same origin policy, when using jQuery.get() method, where the request will not be successfully executed, if data-source is from a different domain, subdomain, or protocol.

$(function () {
    $.get("dist/css/bootstrap.min.css", function (data) {
        var version = data.match(/v[.\d]+[.\d]/);
        alert(version);
    });
});

在线示例


上面的在线示例基于从 jsfiddle.net 但不是从 getbootstrap.com ,因为已经提到的安全原因,并提取一个注释,应该显示相应的后
运行按钮。

The online example above, is based on grabbing local file from jsfiddle.net but not from getbootstrap.com, because of the security reasons that were already mentioned, and extracting a comment, which should display accordingly after you hit Run button.

您也可以通过转到 getbootstrap.com ,打开控制台并粘贴代码。运行后,您将获得 显示的 当前版本

You could also test it just by going to getbootstrap.com, opening a console and pasting the code. After you run it, you will get the current version of Bootstrap displayed, which is v3.0.3 at the moment.

这篇关于如何检测JavaScript使用哪个Bootstrap版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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