问题描述
我一直在查看&来自Bootstrap的。没有任何模块化在常见别名下。对于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.
假设包含一个显示版本的注释(实际上总是这样):
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
*/
请记住,当使用方法,其中请求将不会成功执行,如果数据源来自不同的域, ,或协议。
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);
});
});
您也可以通过转到,打开控制台并粘贴代码。运行后,您将获得 显示的 当前版本,
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版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!