2012-07-12 58 views
1

我創建使用JavaScript的新窗口(W/jQuery的),我用這樣的代碼一些節點添加到新窗口的身體:CSS在新創建的窗口

var consoleWindow = window.open('','','width=460,height=345'); 
$(consoleWindow.document).find('body').append($("#debug_console")); 

問題是我天真地認爲父窗口的CSS規則將適用於子窗口中的節點,而不是我沒有格式化的HTML。我將如何在新窗口中應用CSS?謝謝你的幫助。

回答

5

只要使用類似這樣

$(consoleWindow.document).find('head').append('<link rel="stylesheet" href="style.css" type="text/css" />'); 

但你要鏈接的href指向你的CSS文件。