动态载入script,js跨站点访问数据

1.可以通过动态加载script标签来跨域载入变量。
跨域直接用ajax方式无法载入,但可以用scrit标签载入。
使用时可能有一些问题(没试成功),但可以先把值放到dom中传一下。

2.script标签有addEventListener onload事件,这上面处理变量载入成功以后事。

3.tor有时访问页面,需要加一个随机数强制刷新(未详测)

4.tor的ip更换很缓慢且不定,有时几十秒,有时几十分钟都没有更新ip。

5.tor主页显示的ip变得很快,实际上没有变。未知原因。

//动态载入Script标签(处理内存泄漏问题)
function OnScriptLoaded()
{
    
var status = document.title;
}

function LoadScript()
{
    
var script=document.getElementById('ScriptId');
    
if (script)
    {
        document.getElementsByTagName(
"head")[0].removeChild(script);
        script 
= null;
    }

    script
=document.createElement("script");
    script.type
="text/javascript";
    script.id
="ScriptId";
    script.addEventListener(
"load", OnScriptLoaded, false);
    script.src
="http://www.guoguoer.cn/abcd.php?p=u&rnd=" + Math.random();
    document.getElementsByTagName(
"head")[0].appendChild(script);
}
posted @ 2009-10-11 23:08  果果’er  阅读(1826)  评论(0编辑  收藏  举报