2014-02-14 166 views
2

這是我的,它不工作。請幫忙。如何在新窗口中打開textarea?

var myWindow = window.open("","","width=600,height=450"); 
newContent = myWindow.document.createElement("textarea"); 
myWindow.document.appendChild(newContent); 
+0

不工作怎麼樣?你有沒有檢查你的JavaScript控制檯的錯誤? –

+0

可能是彈出窗口阻止程序問題? – dfsq

+0

不是彈出式窗口攔截器問題。 – SKaul

回答

1
var myWindow = window.open("","","width=600,height=450"); 
newContent = myWindow.document.createElement("textarea"); 
myWindow.document.appendChild(newContent); 

發送一個錯誤:

Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node': Nodes of type 'INPUT' may not be inserted inside nodes of type '#document'.

所以只是改變

myWindow.document.appendChild(newContent); 

myWindow.document.body.appendChild(newContent); 

小提琴:http://jsfiddle.net/hjUrP/

+0

謝謝,它解決了我的問題。 – SKaul

+0

我可以根據內容調整這個textarea和窗口的大小嗎? – SKaul

+0

你能多解釋一下嗎?或者更好的,你可以問新的問題,並在評論中鏈接它?它可以攔截其他用戶。 – pbenard

2

EXAMPLE

function openWin(){ 
    var myWindow = window.open("","","width=600,height=450"); 
    myWindow.document.write("<textarea rows='30' cols='70'></textarea>"); 
} 
+0

謝謝洛倫佐,它的作品! – SKaul