這個自然會想到用window.open()方法
但新窗體的內容並不是固定的
如果我們建立一個 tip.html 的靜態頁面,專門用來讓window.open打開,打開之後再用js設置窗體的內容
這樣做也能滿足要求,但是有沒有更好的方法呢?
下面的方法可以不用建一個專門的靜態頁面,而是每次都是打開一個臨時窗口,窗體的內容也是動態構造的
請看代碼:
openWindow.document.writeln('<html>');
openWindow.document.writeln('<TITLE>Open Test</TITLE>');
openWindow.document.writeln('<BODY>');
openWindow.document.writeln('<center>');
openWindow.document.writeln('Hello! New window opened!');
openWindow.document.writeln('<br><br>');
openWindow.document.writeln('<input type=button value=close οnclick=window.close()>');
openWindow.document.writeln('</center>');
openWindow.document.writeln('</BODY>');
openWindow.document.writeln('</HTML>');
openWindow.document.close(); " >