我要写一个页面 有个文本框 输入URL 就创建一个iframe 
再通过本页面给iframe注册函数  会出现 拒绝访问
url 是跨域的 
 function frameLoad(id) {
            window.frames[id].document.write("<script type=\"text/javascript\" scr=\"http://localhost:53534/netCenter/js/include.htm\" ><\/script>");        }

解决方案 »

  1.   


            var divTag = 10;
            function setlocation(obj) {
                divTag++;
                var url = document.getElementById(obj).value;
                var newDIV = document.createElement("div");
                newDIV.setAttribute("dname", "content_div_" + divTag);
                if(url.indexOf("//")<=0){
                    url = "http://" + url;
                }
                document.body.appendChild(newDIV);
                showContent(newDIV.dname);
                newDIV.innerHTML = "<iframe width=\"100%\" id=\"content_frame_" + divTag + "\" src=\"" + url + "\" onload=\"frameLoad(this.id)\" ></iframe>";
            }        function frameLoad(id) {debugger
                window.frames[id].document.write("<script type=\"text/javascript\" scr=\"http://localhost:53534/netCenter/js/include.htm\" ><\/script>");        }<input type="text" id="txturl" /><input type="button" onclick="setlocation('txtUrl')" />
    比如: 在文本框输入 www.baidu.com 
    就创建一个iframe 在iframe的onload事件中调用frameLoad 函数
    红色部分会出错
      

  2.   

    应该是不行的,不然你随便iframe个人家的页面,就随意调用人家的方法做事
    那貌似就是传说中的黑客了吧
      

  3.   

    你这样写  window.frames[id].document.write("")
    就是不跨域的话  也有问题呀  破坏原来的页面了呀
      

  4.   

    使用ajax获取url的HTML页面代码,添加你需要的方法后,写到iframe里面去~~
      

  5.   


    好主意 今天刚刚 看了  Google 和 Opera 浏览器 我可以直接  用 js写个浏览器    哈哈哈  谢谢 
      

  6.   

    如何将html 写入到iframe 里面呢
      

  7.   


    var strHTML = "<html><body>内容。。<body></html>";
    如何将strHTML的内容加到iframe中
      

  8.   

    楼主好像忘了一个问题,ajax本身就是禁止跨域的
      

  9.   

    在两个页面中都加上document.domain='localhost';