可以用window.name判断!
但是我不是很明白你的问题的意思!
给你举一个例子:
<a href=# target="newwindow">Click</a>
点击它弹出一个新窗口,窗口名为newwindow.
这时,你可以用alert(window.name)得到newwindow这个值!
...说不清楚好象,你到底要问什么?
但是我不是很明白你的问题的意思!
给你举一个例子:
<a href=# target="newwindow">Click</a>
点击它弹出一个新窗口,窗口名为newwindow.
这时,你可以用alert(window.name)得到newwindow这个值!
...说不清楚好象,你到底要问什么?
比仿你打开一个myweb.htm的页子,
并且你同时也打开其它几个页子
那么a.htm将会判断:
如果当前存在窗口名称为newwindow的叶子,则a.htm中有一个值返回1
如果不存在,则myweb.htm中有一个值返回0请问我如何编写myweb.htm这个页子??
假如能够历遍的话,那么判断是否有newwindow很简单了.
这时,myweb.htm可以这样.
如果不存在,给自己返回一个值很简单嘛.
如果存在,要给a.htm返回值,你只需要在myweb.htm里面:
window.opener=a.htm的窗口名
然后再用opener传值给a.htm就可以了!关键部分没有搞定,说了等于白说.我们两个一起等待高手赐教!
<SCRIPT>
<!--
self.resizeTo(300, 300);
self.moveTo(0, 200);var hasChild = false;var child = null;function openChild()
{
if ( hasChild )
{
child.document.body.innerHTML += 'hey! I found you!<BR>';
}
else
{
child = window.open('', 'child', 'width=300, height=200, scrollbars=no');
child.opener = self; child.document.writeln('<HTML>');
child.document.writeln('<HEAD>');
child.document.writeln('<TITLE>child</TITLE>');
child.document.writeln('<SCRIPT>');
child.document.writeln('self.moveTo(400, 200);');
child.document.writeln('');
child.document.writeln('window.onload =');
child.document.writeln(' function load()');
child.document.writeln(' {');
child.document.writeln(' if ( !opener.closed )');
child.document.writeln(' {');
child.document.writeln(' opener.hasChild = true;');
child.document.writeln(' }');
child.document.writeln(' }');
child.document.writeln('');
child.document.writeln('window.onunload =');
child.document.writeln(' function unload()');
child.document.writeln(' {');
child.document.writeln(' if ( !opener.closed )');
child.document.writeln(' {');
child.document.writeln(' opener.hasChild = false;');
child.document.writeln(' }');
child.document.writeln(' }');
child.document.writeln('</SCRIPT>');
child.document.writeln('</HEAD>');
child.document.writeln('<BODY>');
child.document.writeln('</BODY>');
child.document.writeln('</HTML>');
child.document.close();
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE=button VALUE='Open child Window' ONCLICK='openChild()'>
</BODY>
</HTML>
<HEAD>
<TITLE>parent</TITLE>
1.1 根据 hasChild 标志判断是否开启了名字为child的子窗口
1.2 如果hasChild == true,表示已经开启,则在子窗口中写一行字.
1.3 如果hasChild == false,表示未开启,则新开一个名字为child的子窗口.并输入需要的数据.2. 子窗口
2.1 设定onload事件,当子窗口加载时,设定主窗口的hasChild为true,意即告诉主窗口 “俺在,请不要克隆俺.”
2.2 设定unload事件,当子窗口刷新或者是关闭时,设定主窗口的hasChild为false,意即告诉主窗口 “俺即将重生或者翘翘,有空可以重新call我出来”.另:在子窗口中的 if ( !opener.cosed ) 表示检测主窗口是否已经关闭.如果主窗口已经关闭,子窗口就没有必要向主窗口汇报当前动向.
<HTML>
<HEAD>
<TITLE>parent</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<SCRIPT>
<!--
self.resizeTo(300, 300);
self.moveTo(0, 200);var child = null;function openChild()
{
if ( child == null || (child != null && child.closed) )
{
document.body.innerHTML += child == null ? 'child == null<BR>' : 'child != null && child.closed<BR>';
child = window.open('child.htm', 'child', 'width=300, height=200, scrollbars=yes');
child.opener = self;
}
else
if ( !child.closed )
{
document.body.innerHTML += '!child.closed<BR>';
child.document.body.innerHTML += 'hey! I found you!<BR>';
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE=button VALUE='Open child Window' ONCLICK='openChild()'>
<BR>
</BODY>
</HTML>
<!----------parent.htm end---------->二、子窗口child.htm代码:<!----------child.htm begin---------->
<HTML>
<HEAD>
<TITLE>child</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
</HEAD>
<BODY>
<BR>I'm child window<BR>
</BODY>
</HTML>
<!----------child.htm end---------->
var head = null;
var html = child.document.body.parentNode;
for ( i = 0; i < html.children.length; i++ )
{
if ( html.children(i).tagName == 'HEAD' )
{
head = html.children(i);
break;
}
}
if ( head != null )
{
var script = child.document.createElement('SCRIPT');
script.src = 'control.js';
script.charset = 'UTF-8';
head.appendChild(script);
}2. 接着将javascript代码写在control.js文件中.就可以了.比如:
// control.js begin// 移动子窗口
self.moveTo(400, 200);// control.js end四、本程序是随手写的,没有经过严密的思考,再加上本人水平很弱,所以各位如果有更好的方法或改进其中的不足之处,并拿出来共享,本人不胜感激.
<HTML>
<HEAD>
<TITLE>parent</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<SCRIPT>
<!--
function child(win, url, name, features)
{
this.win = win;
this.url = url;
this.name = name;
this.features = features;
}function CheckWindow()
{
this.children = new Array();
this.count = 0;
this.insert =
function(child)
{
this.children[this.count++] = child;
}
this.update =
function(i, child)
{
this.children[i] = child;
}
this.search =
function(name)
{
for ( i = 0; i < this.count; i++ )
{
if ( this.children[i].name == name )
{
return i;
}
} return -1;
}
this.check =
function(i)
{
if ( this.children[i].win != null && !this.children[i].win.closed )
{
return true;
}
return false;
}
this.open =
function(url, name, features)
{
var i = -1;
if ( (i = this.search(name)) == -1 )
{
win = window.open(url, name, features);
win.opener = self;
this.insert(new child(win, url, name, features));
}
else
{
if ( this.check(i) )
{
alert('名称为 "' + this.children[i].name + '" 的窗口已开启');
}
else
{
win = window.open(url, name, features);
win.opener = self;
this.update(i, new child(win, url, name, features));
}
}
}
}var cw = new CheckWindow();
//-->
</SCRIPT>
</HEAD>
<BODY>
url: <INPUT TYPE=text Name='url' VALUE='http://cn.yahoo.com'><BR>
name: <INPUT TYPE=text NAME='windowName'><BR>
features: <INPUT Type=text NAME='features'><BR>
<INPUT TYPE=button VALUE='open' onClick='cw.open(url.value, windowName.value, features.value)'>
<A HREF="javascript:cw.open(url.value, windowName.value, features.value)">open</A>
<BR>
</BODY>
</HTML>
<!----------parent.htm end---------->
<body>
<a href="http://www.163.com" target="winName">163电子信箱</a>
</body>现在我需要制作一个符合下面条件的网页:
1.名字为winName的网页不被覆盖
2.能证明当前已经存在一个名字为"winName"的网页