Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 打开iframe src到新页面_Javascript_Html_Iframe - Fatal编程技术网

Javascript 打开iframe src到新页面

Javascript 打开iframe src到新页面,javascript,html,iframe,Javascript,Html,Iframe,我的网页首先打开app.html。单击登录后,我需要打开index.html,我在iframe中打开它,并在javascript中动态创建iframe。因此,要打开该框架,我会将其附加到document.body。但它会附加到app.html的主体。但我需要在新页面中打开 var el = document.createElement("iframe"); el.setAttribute('id', 'ifrm'); el.setAttribute('name', 'ifrm'); el.set

我的网页首先打开app.html。单击登录后,我需要打开index.html,我在iframe中打开它,并在javascript中动态创建iframe。因此,要打开该框架,我会将其附加到document.body。但它会附加到app.html的主体。但我需要在新页面中打开

var el = document.createElement("iframe");
el.setAttribute('id', 'ifrm');
el.setAttribute('name', 'ifrm');
el.setAttribute('src', '/index/index.html');
el.setAttribute('width', '100%');
el.setAttribute('height', '100%');
el.setAttribute('scrolling', 'no');
document.body.appendChild(el);

您可以使用此选项在新窗口中打开:

var myWindow = window.open("/index/index.html");

您必须在当前页面上分层iframe

el.style.position='绝对'; el.style.top=0;
el.style.left=0

你的问题有点不清楚你想做什么。答案取决于以下因素:

  • 您是想将
    index.html
    添加到
    app.html
    还是代替它

  • 如果两个窗口都要打开,那么是否要在新窗口中打开

  • 如果是这样,您是否需要常规窗口(即与原始窗口大小相同,无需修改)。是的,然后使用JavaScript:

    newWin=window.open(“index.html”,“我的应用程序的主窗口”,winOptions)

  • 或者一个特定大小的窗口,带有其他修改(没有导航栏,没有地址栏等)-换句话说,您想要一个弹出窗口吗

    
    JavaScript弹出窗口示例
    函数loginCheck(){
    //isLoggedIn是一个设置为检查登录名的布尔变量
    如果(isLoggedIn){
    弹出();
    }
    }
    函数popon(){
    var-winOptions=“”;
    winOptions+=“位置=1”;
    winOptions+=“状态=0”;
    winOptions+=“滚动条=0”;
    winOptions+=“宽度=100”;
    winOptions+=“高度=100”;
    newWin=window.open(
    “index.html”,
    “我的应用程序的主窗口”,
    winOptions
    );
    newWin.moveTo(400300);//向下300像素,
    //右边400像素
    }
    JavaScript弹出窗口示例
    
  • 还是要在新选项卡中打开
    index.html

    只需在锚定标记中使用
    target
    属性,将值设置为
    new
    ,例如
    您的问题有点令人困惑。。。您是否尝试在原始app.html之外打开index.html N,作为弹出窗口、新选项卡或在同一窗口/选项卡/框架中打开,换句话说,是要替换它?请提供更多信息,我们可以更好地帮助您。
    
    <html>
      <head>
        <title>JavaScript Popup Example</title>
        <script type="text/javascript">
    
          function loginCheck(){
            //isLoggedIn is a boolean variable you've set to check login
            if (isLoggedIn) {  
              popup();
            }
          }
          function popon(){
            var winOptions = "";
            winOptions += "location=1, ";
            winOptions += "status=0, ";
            winOptions += "scrollbars=0, ";
            winOptions += "width=100, ";
            winOptions += "height=100";
            newWin = window.open(
              "index.html", 
              "My App's Main Window", 
              winOptions
            );
            newWin.moveTo(400, 300);  //300 pixels down, 
                                      //400 pixels to the right
          }
        </script>
      </head>
      <body onload="javascript: loginCheck()">
        <h1>JavaScript Popup Example</h1>
      </body>
    </html>