按名称引用窗口? [英] Referencing windows by name?

查看:73
本文介绍了按名称引用窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


是否可以通过名称引用窗口,而无需执行类似

这样的事情:

open(,''windowName'');

如果没有带有这样的

名称的窗口,open方法将打开一个空白窗口。


我正在尝试在两个窗口之间组织导航结构,来自同一主机的内容为

..我一直在尝试以下方法:


''内容页面''链接回菜单:

< a href =" main.asp" onClick =" return openMenuWindow(this.href);" >输入< / a>


''菜单页''链接到各种内容页面:

< a href =" content.asp" onClick =" return openContentWindow(this.href);"

输入< / a>




功能如下。我的最新消息问题是链接在同一页面打开了

,而不是两页。但是,我有一个偷偷摸摸的怀疑,我正在努力工作,而且正确的技术很多

更简单。


任何关于如何让这两个窗户互相交谈的建议将是

非常欢迎!


var contentWindow = null;

//菜单窗口应使用此功能打开内容窗口。

函数openContentWindow(pageUrl)

{

if(contentWindow!= null &&

String(contentWindow.location)== pageUrl)

{

contentWindow.focus();

返回false;

} //结束如果

contentWindow = window.open(pageUrl," contentWindow");

contentWindow .menuWindow = window;

contentWindow.focus();

} //结束openContentWindow函数


//内容窗口应该是使用此函数打开菜单窗口。

函数openMenuWindow(pageUrl)//(pageUrl,pageName,w,h,scroll,pos)
{

if(window.menuWindow!= null&&

!window.menuWindow.closed)

{

window.open(,''main'')。focus();

return;

} //结束如果


var pageName =''main'';

var w ='''800'';

var h ='' 450'';

var scroll =''no'';

var pos =''center'';


window.name =" contentWindow" ;;

var LeftPosition =(screen.width)?(screen.width -w)/ 2:100;

var TopPosition =( screen.height)?(screen.height-h)/ 2:100;


var settings =

''width =''+ w +

'',height =''+ h +

'',top =''+ TopPosition +

'',left =''+ LeftPosition +

'',scrollbars =''+滚动+


'',location = no,directories = no,status = no,menubar = no,toolbar = no ,resizable = no'';


var menuWindow = window.open(pageUrl, pageName,settings);

menuWindow.focus();

返回false;

} //结束openContentWindow函数


Rob

:)

解决方案

Robert Mark Bram写道:

有没有办法按名称引用一个窗口而不做像
这样的事情:
open(,''windowName'');
open方法会打开一个空白窗口如果没有带有这样名称的窗口。




var w = window.open(''''''''windowName'',' 'featuresIfNotDefaults'');

if(w&& !w.closed)

{

...

}

PointedEars

-

apprentice.c - 解析/ etc / magic学习魔法


(来自文件-3.40自述文件)


嗨Thomas!

var w = window.open(''''''''windowName'',''featuresIfNotDefaults'');
if(w&&!w.closed)
{
...
}




但这会打开如果找不到具有所需名称的窗口,则为空白窗口,

这不是我想要的。


我想要一种方法来查明命名窗口在那里,并将焦点改为

如果是的话。如果不是,我希望重新开窗 - 但不是空白的

一个!


Rob

:)


Robert Mark Bram写道:

var w = window.open(''' ',''windowName'',''featuresIfNotDefaults'');
if(w&&!w.closed)
{
...
} 这不是我想要的。




你是对的。对不起,误会了。

我想知道命名窗口是否在那里,并将焦点改为
如果是的话。如果不是,我希望重新制作窗口 - 但不是空白的一个!




以上代码允许获取对新窗口的引用窗口。对于那个

对另一个窗口可以访问的窗口的引用,你需要

在后者的上下文中包含这些信息。简单的方法是

添加一个属性:


w = window.open(...);

...

w2 = window.open(...);

...

if(w&&!w.closed& ;& w2&&!w2.closed)

{

w2.w = w;

w.w2 = w2;

}


在w中,您可以使用self.w2或window.w2访问w2

因为你可以使用`self.w''或'window.w''在`w2''中访问'w'',提供

表示'self''或者'window''引用你正在使用的

DOM中的当前窗口对象(就像在所有知名浏览器中一样。)


你可以也可以通过引用另一个窗口作为属性

的开启窗口,直到后者仍然存在并且如果你使用

全局变量(只要以上可以是提供)。在'w'':


if(opener&&!opener.closed&& opener.w2&&!opener.w2.closed)

{

...

}

else

{

...

}


和'w2'分别:


if(opener& ;&!opener.closed&& opener.w& amp;!opener.w.closed)

{

...

}

其他

{

...

}


如前所述(Google是你的朋友!),没有参考

你无法访问其他窗口。没有Window对象的集合

(除非你实现一个。)

HTH


PointedEars


Hi All!

Is there a way to reference a window by name without doing something like
this:
open (, ''windowName'');
The open method will open a blank window if there is no window with such a
name.

I am trying to organise a navigation structure between two windows with
content from the same host.. I have been trying the following:

The ''content pages'' link back to the menu with this:
<a href="main.asp" onClick="return openMenuWindow(this.href);" >enter</a>

And the ''menu page'' links to various content pages with this:
<a href="content.asp" onClick="return openContentWindow(this.href);"

enter</a>



The functions are below.My latest problem is that the links are opening up
in the same page, rather than two pages. However, I have a sneaking
suspicion that I am trying too hard and the correct technique is much
simpler.

Any advice on how to get these two windows talking to each other would be
most welcome!

var contentWindow = null;
// Menu window should use this function to open a content window.
function openContentWindow (pageUrl)
{
if (contentWindow != null &&
String(contentWindow.location) == pageUrl)
{
contentWindow.focus();
return false;
} // end if
contentWindow = window.open (pageUrl, "contentWindow");
contentWindow.menuWindow = window;
contentWindow.focus();
} // end openContentWindow function

// Content window should use this function to open a menu window.
function openMenuWindow (pageUrl)//(pageUrl, pageName, w, h, scroll, pos)
{
if (window.menuWindow != null &&
!window.menuWindow.closed)
{
window.open (, ''main'').focus();
return;
} // end if

var pageName = ''main'';
var w = ''800'';
var h = ''450'';
var scroll = ''no'';
var pos = ''center'';

window.name="contentWindow";
var LeftPosition=(screen.width)?(screen.width-w)/2:100;
var TopPosition=(screen.height)?(screen.height-h)/2:100;

var settings=
''width=''+w+
'',height=''+h+
'',top=''+TopPosition+
'',left=''+LeftPosition+
'',scrollbars=''+scroll+

'',location=no,directories=no,status=no,menubar=no, toolbar=no,resizable=no'';

var menuWindow = window.open (pageUrl, pageName, settings);
menuWindow.focus();
return false;
} // end openContentWindow function

Rob
:)

解决方案

Robert Mark Bram wrote:

Is there a way to reference a window by name without doing something like
this:
open (, ''windowName'');
The open method will open a blank window if there is no window with such a
name.



var w = window.open('''', ''windowName'', ''featuresIfNotDefaults'');
if (w && !w.closed)
{
...
}
PointedEars
--
apprentice.c - parses /etc/magic to learn magic

(from the file-3.40 README)


Hi Thomas!

var w = window.open('''', ''windowName'', ''featuresIfNotDefaults'');
if (w && !w.closed)
{
...
}



But this opens a blank window if no window with the desired name is found,
which is not what I want.

I want a way to find out if the named window is there, and change focus to
it if it is. If it is not, I wish to make the window anew - but not a blank
one!

Rob
:)


Robert Mark Bram wrote:

var w = window.open('''', ''windowName'', ''featuresIfNotDefaults'');
if (w && !w.closed)
{
...
}
But this opens a blank window if no window with the desired name is found,
which is not what I want.



You are right. Sorry, misunderstood that.
I want a way to find out if the named window is there, and change focus to
it if it is. If it is not, I wish to make the window anew - but not a blank
one!



The above code allows for getting a reference to the new window. For that
reference to the window to be accessible by another window, you need to
include this information in the context of the latter. The easy way is to
add a property:

w = window.open(...);
...
w2 = window.open(...);
...
if (w && !w.closed && w2 && !w2.closed)
{
w2.w = w;
w.w2 = w2;
}

In `w'' you then can access `w2'' with `self.w2'' or `window.w2'' as well
as you can access `w'' in `w2'' with `self.w'' or `window.w'', provided
that `self'' or `window'' references the current window object in the
DOM you are using (as it is in all well-known browsers.)

You could also access the other window by referencing it as property
of the opener window until the latter is still there and if you use
global variables (as long as the above can be provided). In `w'':

if (opener && !opener.closed && opener.w2 && !opener.w2.closed)
{
...
}
else
{
...
}

And in `w2'' respectively:

if (opener && !opener.closed && opener.w && !opener.w.closed)
{
...
}
else
{
...
}

As posted many times before (Google is your friend!), without references
you cannot access other windows. There is no collection of Window objects
(unless you implement one.)
HTH

PointedEars


这篇关于按名称引用窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆