用window.open方法打開新窗口顯示提示信息

有時候我們需要打開一個新窗口用來顯示提示信息
這個自然會想到用window.open()方法
但新窗體的內容並不是固定的
如果我們建立一個 tip.html 的靜態頁面,專門用來讓window.open打開,打開之後再用js設置窗體的內容
這樣做也能滿足要求,但是有沒有更好的方法呢?
下面的方法可以不用建一個專門的靜態頁面,而是每次都是打開一個臨時窗口,窗體的內容也是動態構造的
請看代碼:
<input type=button value=open οnclick="openWindow=window.open();
    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(); " >
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章