简体   繁体   English

首次加载时如何从弹出窗口返回对父窗口的关注

[英]How to return focus on parent window from a pop window while loading first time

I am working on a website. 我正在网站上。 Where while loading website first time opening index page with one pop window. 加载网站时第一次用一个弹出窗口打开索引页面。 First my problem is I want to minimize this pop window automatically while loading first time and focus return to website without any click in website. 首先,我的问题是我想在首次加载时自动最小化此弹出窗口,然后将焦点返回到网站,而无需单击任何网站。

Here is my code in index page I write this function: 这是我编写此函数的索引页中的代码:

myFunction();
 function myFunction() {
   //var myWindow = window.open("music.php", "", "width=320,height=60");

   var myWindow = window.open("music.php", "", "directories=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0,scrollbars=no,resizable=no,left=-100000000, top=100000, width=320, height=1, display=none","visibility=hidden");
    //myWindow.moveTo(0, 0);
}

And pop window having page extension music.php which should be minimize automatically and focus return to index page without any click on website. 弹出窗口具有扩展名music.php ,应该自动将其最小化,并且无需单击任何网站即可将焦点返回索引页。

I have already try with set the focus of a popup window to website everytime , but it was also not working. 我已经尝试过每次都将弹出窗口的焦点设置为网站 ,但是它也不起作用。

Well, The window object has an opener property as well. 好了,window对象也具有opener属性。 When we open the browser, that property is null, and when we open a popup , it points to the window the popup has been opened through. 当我们打开浏览器时,该属性为null,当我们打开一个popup时,它指向打开该弹出窗口的窗口。

I think something like this should suffice. 我认为这样就足够了。

myFunction();
 function myFunction() {

   var myWindow = window.open("music.php", "", "directories=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0,scrollbars=no,resizable=no,left=-100000000, top=100000, width=320, height=1, display=none","visibility=hidden");

   myWindow.opener.focus()   // can also do window.focus()

}

The execution of JS should not stop, but if it does, you have to add the focus code to your child page/popup page.(Depending on varying browsers) JS的执行不应该停止,但是如果这样做,则必须将焦点代码添加到子页面/弹出页面中(取决于不同的浏览器)

like 喜欢

popupHTMLJS.js popupHTMLJS.js

focusParent();
function focusParent(){
    parent = window.opener;
    parent.focus()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM