JS 打开新窗口

JS 打开新窗口,第1张

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

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

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

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

2一个例子

1)主窗口mainhtml,

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

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

mainhtml

复制代码代码如下:

<HTML>

<HEAD>

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

</HEAD>

<script>

functionshowmodal()

{

varret=windowshowModalDialog("subhtmltemp="+Mathrandom());

alert("subreturnvalueis"+ret);

}

</script>

<BODY>

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

</BODY>

</HTML>

subhtml

<HTML>

<HEAD>

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

</HEAD>

<script>

functionreturnMain()

{

windowreturnValue="returnfromsub";

windowclose();

}

</script>

<BODY>

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

</BODY>

</HTML>

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

方式二:

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

script language=javascript>

function insertHtml(HtmlCode)

{

var win=windowcontent_htmlidEditboxdocument;//其中编辑区域是gledithtm中的一个iframe,id是idEditbox

windowcontent_htmlidEditboxfocus();//是编辑器获得焦点,防止代码插入在编辑器外地方

winselectioncreateRange()pasteHTML(HtmlCode)//在光标的位置插入html代码

}

</script>

>

1、打开子窗口

newWindow = windowopen(“newhtm”, "", "width=400,height=300 "); //打开子窗口newhtm,并且返回子窗口的句柄window变量newWindow

2、获取子窗口的值

var a= newWindowdocumentgetElementById("T")value;//通过newWindow获取子窗口组件id是T的值

新建两个窗口,一个父窗口,一个子窗口。

_复翱诨袢∽哟翱谟辛街址椒ǎ谝恢址椒ㄊ牵好扛龆加幸桓_ontentWindow属性, 通过contentWindow可获取子窗口;第二种方法是:window对象有frames属性,它是一个类数组对象,可以通过数字或窗体名进行索引。

_庋胝夷歉龃翱诰涂梢灾付ㄕ夷歉龃翱诹恕

以上就是关于JS 打开新窗口全部的内容,包括:JS 打开新窗口、如何使iframe中页面获得焦点、怎样在js中从父窗口获取子窗口的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9608998.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存