如何用JS实现在当前页面打开新页面,而不是在新窗口打开?

JavaScript014

如何用JS实现在当前页面打开新页面,而不是在新窗口打开?,第1张

其实楼上说的就是javascript代码,只是有点写错了,\x0d\x0a\x0d\x0a\x0d\x0afunction open(html){\x0d\x0a\x0d\x0awindow.open(html,'_self') \x0d\x0a}\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a你的按钮这样写\x0d\x0a\x0d\x0a \x0d\x0a\x0d\x0a补充回答:\x0d\x0a\x0d\x0a首先给你说的代码绝对没错,你可以自己试试呀\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0afunction on(html){\x0d\x0a\x0d\x0awindow.open(html,'_self') \x0d\x0a}\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a \x0d\x0a\x0d\x0a \x0d\x0a\x0d\x0a看出来了,表单的问题,兰州可以把form表单去掉就可以了。

请采用网页对话框的方式  showModalDialog

showModalDialog是jswindow对象的一个方法,和window.open一样都是打开一个新的页面。

区别是:showModalDialog打开子窗口后,父窗口就不能获取焦点了(也就是无法操作了)。

可以在子窗口中通过设置window.returnValue的值,让父窗口可以获取这个returnvalue.

2.一个例子

1)主窗口main.html,

2)在主窗口中通过showModalDialog的方式打开子窗口sub.html

3)在子窗口中设置returnValue返回给主窗口使用

main.html

复制代码代码如下:

<HTML>

<HEAD>

<METANAME="GENERATOR"Content="oscar999">

</HEAD>

<script>

functionshowmodal()

{

varret=window.showModalDialog("sub.html?temp="+Math.random())

alert("subreturnvalueis"+ret)

}

</script>

<BODY>

<INPUTid=button1type=buttonvalue="opensub"name=button1onclick="showmodal()">

</BODY>

</HTML>

sub.html

<HTML>

<HEAD>

<METANAME="GENERATOR"Content="oscar999">

</HEAD>

<script>

functionreturnMain()

{

window.returnValue="returnfromsub"

window.close()

}

</script>

<BODY>

<INPUTid=button1type=buttonvalue="returnandclose"name=button1onclick="returnMain()">

</BODY>

</HTML>

这种目前只有IE可用,其它浏览器都不可用了

方式二:

采用其它js框架,弹出对话框的模式