js动态创建iframe,无法加载src所指定的页面,请问是什么原因?
var div = document.getElementById("dialog1");
var iframe = document.createElement("iframe");
//iframe.setAttribute("src","test.html");
iframe.src = 'test.html';
iframe.style.width = "100%";
iframe.style.height = "100%";
div.appendChild(iframe);
$("#dialog1").dialog('open');

解决方案 »

  1.   

    src指向的地址在这种写法是没问题的<iframe  src="test.html" style="width:100%;height:100%;"></iframe>
      

  2.   

    div.appendChild(iframe);
    document.body.appendChild(div)
      

  3.   

    你的这个方法也不可以啊。还有就是我的div不是动态创建的,原本就在body里,为什么还要加document.body.appendChild(div)啊?
      

  4.   

    //*******************************************// 弹层调用iframe设置ID值jQuery.setInputPid = function(options) {    /* 定义初始变量 */    var defaults = {        title : '',        set_url : '',        w : 500,        h : 300,        x : "center",        y : "center"    };    var opts = $.extend(defaults, options);    data = '<iframe src="'+opts.set_url+'" marginheight="0" marginwidth="0" frameborder="0" style="border:0px;width:100%;height:100%;"></iframe>';    /* 创建一个DIV */    $("<div>",{id:"ilinju_select_div",html:data})    .dialog({        bgiframe:true,        closeOnEscape:true,        draggable:true,        modal:false,        resizable:true,        stack:true,        hide:"slide",        show:"slide",        height:opts.h,        width:opts.w,        position:[opts.x,(parseInt(opts.y) + 20)],        title:opts.title,        close:function(){$(this).html("");$(this).remove();}    });};
      

  5.   

    那你在说的明确点
    无法加载 具体是什么意思?你调试过了没? 确认这个src无法加载吗?如果页面直接写iframe 能否加载这个src?
      

  6.   

    iframe.src = 'http://www.google.com';
    这个能加载吗