[英]Getting parameter value from Javascript dynamic script
I have this piece of JS code: 我有这段JS代码:
(function() {
var s = document.createElement('script');
s.id = 'LeadiDscript_campaign';
s.type = 'text/javascript';
s.async = true;
s.src = (document.location.protocol + '//d1tprjo2w7krrh.cloudfront.net/campaign/aa545531-face-feed-cafe-4c5e1302580a.js');
var LeadiDscript = document.getElementById('LeadiDscript');
LeadiDscript.parentNode.insertBefore(s, LeadiDscript);
});
It returns parameters that I can only access/view from Firebug. 它返回我只能从Firebug访问/查看的参数。 The parameter name is 's'.
参数名称为“ s”。 How can I access that parameter so that I can view it and display it as an HTML element?
如何访问该参数以便我可以查看它并将其显示为HTML元素?
If you want to access a variable from a private scope within the global scope you'll need to bind it to the global scope or a child of it. 如果要从全局范围内的私有范围访问变量,则需要将其绑定到全局范围或其子级。
(function() {
var s = document.createElement('script');
window.s = s;
...
});
Then later, somewhere in your code, in a completely different scope, you can access it using either window.s
or just s
if there are no local variables of that name. 再后来,在你的代码的某个地方,在一个完全不同的范围,您可以使用访问
window.s
或只是s
如果有该名称的任何局部变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.