如何在不刷新的情况下将焦点设置到子窗口? [英] How to set the focus to a child window without refreshing it?
问题描述
我有一个包含四个链接的网页,每个链接打开一个弹出窗口.我正在使用通用的JavaScript函数打开弹出窗口,如下所示
I am having a web page which contain four links, each link open a popup window. I am using a common JavaScript function to open popup window, as given below
function OpenPopup(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no,
directories=no, status=no, menubar=no, scrollbars=Yes, resizable=no,
copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
targetWin.focus();
}
当我单击链接时,它将打开一个弹出窗口,其中包含一个数据输入表单,我在该表单中输入了一些信息.然后,我需要从其他弹出窗口中查看其他信息,因此我回到主窗口,单击另一个链接,一个新的弹出窗口将打开,其中包含我需要查看的信息.我得到了信息并关闭了此弹出窗口,所以现在我在主窗口中,然后再次单击该数据输入表单的链接,因此弹出窗口出现了,但是我丢失了我输入的信息,这是因为我将再次打开弹出窗口,新的弹出窗口将用相同的名称替换现有的弹出窗口.
When I click on a link it will open a popup window, which contain a data entry form, I entered some information into that form. Then I need to review other information, from other popup window, so i go back to my main window, click on another link, a new popup window will get open which contain the information I need to review. I get the information and close this popup window, so now i am on my main window, then again I click on the link for that data entry form, so the popup window comes up but i lost the information that I have entered, it's because I am opening the popup window once again, and the new popup window will replace the existing popup with the same name.
现在我的问题是:
-
有什么办法,我可以检查父窗口是否已经打开了弹出窗口吗?
Is their any way, I can check out the if popup window is already open from parent window?
如果弹出窗口已经打开,如何将焦点设置到该窗口,而不是重新加载它?
If the popup window is already open how can I just set the focus to it, rather then reloading it?
如何从父窗口引用子窗口,而又不仅仅通过子窗口的名称获得子窗口的对象?
How can I refer a child window from parent window, without having object of child window just by the name of child window?
即使刷新父窗口后,我也可以从父窗口引用子窗口吗?
Can I refer a child window from a parent window, even after refreshing the parent window?
推荐答案
对于1和2,您可以使用此功能
For 1 and 2 , you can use this function
// loads an URL into the popup without reloading it
function popupnr(mylink, windowname, refocus) {
// open the window with blank url
var mywin = window.open('', windowname, 'window attrs here');
// if we just opened the window
if (mywin.closed || (!mywin.document.URL) || (mywin.document.URL.indexOf("about") == 0)) {
mywin.location = mylink;
}
else if (refocus) {
mywin.focus();
}
// return the window
return mywin;
}
-
您不能通过子窗口的名称来引用它.没有window.children.您需要调用
window.open
以获得参考.
是的,可以.但是您需要在调用 window.open
Yes you can. But u need to use the same window name while calling window.open
这篇关于如何在不刷新的情况下将焦点设置到子窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!