2014-02-27 56 views
2

我的網頁打開app.html first.After點擊登錄後,我需要打開index.html,我打開iframe和我動態創建iframe在javascript.so打開我的框架即時追加到document.body.But其追加到app.html.But的身體,我需要在新頁面中打開打開iframe src到新頁面

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); 
+1

你的問題是有點混亂往裏面...你是否試圖打開index.html N ADDITION到原始app.html,作爲一個彈出窗口,作爲一個新的選項卡,或在SAME窗口/ tab/frame - 換句話說要取代它?請提供更多信息,我們可以幫助您更好。 – 2014-05-08 14:08:44

回答

5

你可以使用這個在新窗口中打開:

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

您必須將iframe覆蓋在當前頁面上

el.style.position ='absolute'; el.style.top = 0; el.style.left = 0;

0

你的問題有點不清楚,你試圖做什麼。答案完全取決於之類的東西:

  1. 你試圖打開除到app.htmlindex.html或代替它?

    1. 如果你想同時打開,那麼你想打開一個新的窗口嗎?

      1. 如果是這樣,你想要一個常規的窗口(即與原來的大小相同,沒有修改)。是的,然後使用JavaScript:

        newWin = window.open(「index.html」,「我的應用程序的主窗口」,winOptions);

      2. 或特定大小的窗口,與其他修改(沒有導航欄,沒有地址欄,等) - 換句話說,你想一個彈出窗口

        <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> 
        
    2. 或者您是否想在新選項卡中打開index.html? 只需在錨標記中使用target屬性,並將值設置爲new(例如, <a target="new"...

    3. 如果你試圖取代的index.html /在同一個標​​籤中打開...你都不用做任何事情你href
    4. 如果你想打開app.html內的內容app.html網頁......然後你可以:
      1. 需要使用iframe(已經可以在app.html中標記了(你不需要用JavaScript動態創建它)並加載index.html進入它或...
      2. 使用AJAX加載頁面幕後,而app.html是STILL加載,在窗口/標籤...沒有重新加載或替換它一旦AJAX請求完成,你會n用index.html中的HTML做些什麼...如:
        • 使用普通香草JavaScript來動態創建div(或顯示隱藏的div)並在index.html加載後填充它。
        • 使用(jQuery的)部件,如標籤/標籤集或手風琴,當app.html加載