现在的位置: 首页 > 综合 > 正文

用window.open方法打开新窗口显示提示信息

2018年02月11日 ⁄ 综合 ⁄ 共 868字 ⁄ 字号 评论关闭

有时候我们需要打开一个新窗口用来显示提示信息
这个自然会想到用window.open()方法
但新窗体的内容并不是固定的
如果我们建立一个 tip.html 的静态页面,专门用来让window.open打开,打开之后再用js设置窗体的内容
这样做也能满足要求,但是有没有更好的方法呢?
下面的方法可以不用建一个专门的静态页面,而是每次都是打开一个临时窗口,窗体的内容也是动态构造的
请看代码:

<input type=button value=open onclick="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 onclick=window.close()>'); 
    openWindow.document.writeln('</center>');
    openWindow.document.writeln('</BODY>'); 
    openWindow.document.writeln('</HTML>'); 
    openWindow.document.close(); " >
【上篇】
【下篇】

抱歉!评论已关闭.