[英]passing in script attributes (data-vars) into head.js?
is there a way to pass script attributes into the loading javascript via head.js? 有没有办法通过head.js将脚本属性传递到正在加载的javascript中?
for example script we need to load is in original form like this : 例如我们需要加载的脚本是这样的原始形式:
<script type="text/javascript" charset="utf-8"
src="script.js"
data-vast-src="adscript.js"
data-post-ad-container="content-div"
data-autoplay="true"
data-width="600"
data-height="400">
</script>
so solution we need is something like this : 所以我们需要的解决方案是这样的:
head.js("jquery.js", { url: "script.js", charset: "utf-8", data-vast-src: "adcript.js", data-post-ad-container: "content-div", data-autoplay: "", data-width: "600", data-height: "400" }, function() {
}
we have tried this, but it does not work... 我们已经尝试过了,但是没有用...
No, this is not possible in HeadJS, but you can easily do it yourself 不,这在HeadJS中是不可能的,但是您可以自己轻松地做到这一点
function addScript(url, attributes) {
var s = document.createElement("script");
s.type = "text/javascript";
s.src = url;
for (var item in attributes) {
s.setAttribute(item, attributes[item]);
}
var head = document.head || document.getElementsByTagName("head")[0];
head.insertBefore(s, head.lastChild);
}
var attributes = {
"data-vast-src" : "adscript.js",
"data-post-ad-container": "content-div",
"data-autoplay" : "true",
"data-width" : "600",
"data-height" : "400"
};
addScript("http://...../script.js", attributes);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.