2017-02-23 75 views
0

因此,我知道如何在google中創建一個彈出窗口,並且我知道如何在彈出窗口中編寫,但是如何在彈出窗口中添加其他HTML標記?如何在彈出窗口中編輯html?

我有的HTML代碼如下。

<html> 
<head> 
<script> 
function openWin() 
{ 
myWindow=window.open("","","width=200,height=100"); 
myWindow.document.write("<p>NEW WINDOW<p>"); 
} 
</script> 
</head> 
<body> 
<button onmousedown='openWin();'>Hello</button> 
</body> 
</html> 

正如你所看到的,在執行document.write功能,我有兩個<p>標籤,我也可以用<button>標籤,但我不能用<script>標籤,沒有人知道爲什麼,或者如果它有可能嗎?

+0

http://stackoverflow.com/questions/10946800/how-to-add-script-files-in-child-window-using-javascript –

+0

我覺得這是我們缺少關鍵的是_why_你試圖將腳本標籤寫入彈出窗口?我很難想象需要哪種場景...... –

回答

0

所以你試圖寫一個<script>標籤到你的彈出窗口?你要做這樣的:

<html> 
<head> 
<script> 
function openWin() 
{ 
myWindow=window.open("","","width=200,height=100"); 
myWindow.document.open(); 
myWindow.document.write("<p>NEW WINDOW<p>"); 
myWindow.document.write("<scr" + "ipt>alert('Script works!')</scr"+"ipt>"); 
myWindow.document.close(); 
} 
</script> 
</head> 
<body> 
<button onmousedown='openWin();'>Hello</button> 
</body> 
</html> 

否則父窗口會覺得劇本標籤的東西應該解釋。

+0

謝謝,我會試試這個,然後告訴你我在想什麼。 –

+0

由於某些原因,當我嘗試創建函數時,程序無法正常工作。出於測試目的,我試圖在彈出窗口上重新創建第一頁。 –

-1

您不能在窗口中寫入「< script>」或「</script>」,這些都是不允許的。你必須拆分這些條款。

function openWin() { 
    myWindow=window.open("","","width=200,height=100"); 
    myWindow.document.write("<p>NEW WINDOW<p>"); 
    myWindow.document.write("<scr"); 
    myWindow.document.write("ipt>alert('Script works!')</scr") 
    myWindow.document.write("ipt>"); 
} 
+0

如何複製我自己的答案。 – adam0101

+0

我沒有複製任何東西..思維的不同方式... –

+0

現在你正在被標記的日曆 – adam0101