Javascript JS在弹出窗口中工作吗?
我想要一个包含画布的弹出窗口,但我无法让JS在弹出窗口中工作Javascript JS在弹出窗口中工作吗?,javascript,popup,Javascript,Popup,我想要一个包含画布的弹出窗口,但我无法让JS在弹出窗口中工作 <html> <head> <title> popup test </title> <script language="javascript"> function popup() {OpenWindow=window.open("","","height=250,width=250"); OpenWindow.document.write("<
<html> <head> <title> popup test </title>
<script language="javascript">
function popup()
{OpenWindow=window.open("","","height=250,width=250");
OpenWindow.document.write("<html><body bgcolor=pink>Hello!");
OpenWindow.document.write("<form><input type='button' value='alert' onclick='doalert()'></form> ");
OpenWindow.document.write("</body></html>");
}
function doalert() { alert("Got in");}
</script> </head>
<body>
<input type="button" onclick='popup()' value="click to see new window">
</body></html>
下面是一个玩具程序,它显示了问题,试图让“警报”在弹出窗口中工作
<html> <head> <title> popup test </title>
<script language="javascript">
function popup()
{OpenWindow=window.open("","","height=250,width=250");
OpenWindow.document.write("<html><body bgcolor=pink>Hello!");
OpenWindow.document.write("<form><input type='button' value='alert' onclick='doalert()'></form> ");
OpenWindow.document.write("</body></html>");
}
function doalert() { alert("Got in");}
</script> </head>
<body>
<input type="button" onclick='popup()' value="click to see new window">
</body></html>
弹出测试
函数popup()
{OpenWindow=window.open(“,”,“高度=250,宽度=250”);
OpenWindow.document.write(“你好!”);
OpenWindow.document.write(“”);
OpenWindow.document.write(“”);
}
函数doalert(){alert(“Got in”);}
警报按钮显示在弹出窗口中,单击时闪烁,但不显示警报框。在子窗口中定义DOALRT:
<html> <head> <title> popup test </title>
<script language="javascript">
function popup() {
OpenWindow=window.open("","","height=250,width=250");
OpenWindow.document.write("<html><body bgcolor=pink>Hello!");
OpenWindow.document.write('<script language="javascript">function doalert() { alert("Got in"); } <\/script>');
OpenWindow.document.write("<form><input type='button' value='alert' onclick='doalert()'></form>");
OpenWindow.document.write("</body></html>");
}
</script> </head>
<body>
<input type="button" onclick='popup()' value="click to see new window">
</body></html>
弹出测试
函数popup(){
OpenWindow=window.open(“,”,“高度=250,宽度=250”);
OpenWindow.document.write(“你好!”);
write('function doalert(){alert(“Got in”);});
OpenWindow.document.write(“”);
OpenWindow.document.write(“”);
}
只有在加载新窗口时才能启动“doalert()”。将这些需要在父窗口和子窗口中工作的函数放在一个函数中,并在每个窗口打开时触发它们,即在页面中插入或包含新代码时。在新窗口中打开的文档没有doalert()
函数。它不工作,因为doalert()
功能在父窗口中定义,而不是在弹出窗口中定义。如果必须这样做,请尝试window.opener.doalert
是的,谢谢。现在有趣的问题是浏览器(FF)执行html命令,即使它们在引号内。