在飞行中从外部站点加载js [英] Load js from external site on fly
本文介绍了在飞行中从外部站点加载js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在用户点击按钮时从外部网站加载JS代码。例如:
I want to load JS code from external site when user click on button. For example:
<button onclick="LoadJSFromURL('facebook.com/blablabla')" />
当用户按下按钮时,我们会在文档中添加新脚本:
and when user press button we attach new script to the document:
<script> Share.WorkUrl="http://MySite.com"; Share.UserId=5 </script> <script src="http://Facebookcom/blabalbal" ></script>
然后我们必须执行此脚本。这是真的吗?
and then we must execute this script. Is it real?
推荐答案
检查一下:如何动态加载来自不同域的javascript文件?
var script = new Element("script", {src: "myBigCodeLibrary.js", type: "text/javascript"});
script.onload = script.onreadystatechange = function(){
if (!this.readyState ||
this.readyState == "loaded" || this.readyState == "complete") {
//script is loaded
}
};
这篇关于在飞行中从外部站点加载js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文