简体   繁体   English

javascript window.close,再次

[英]javascript window.close, once again

Im sorry if I havent done my research properly, - but couldnt find the answer I needed, so here goes: 很抱歉,如果我没有正确地进行研究,但找不到所需的答案,因此,这里是:

From my main page I open a new window using mainPlayer = window.open(); 在我的主页上,使用mainPlayer = window.open();打开一个新窗口。

This window stays open until user clicks on a mainPlayer.close(); 该窗口将保持打开状态,直到用户单击mainPlayer.close();。 event. 事件。 (or simply x closes the window) (或简单地x关闭窗口)

However, the idea is to make it possible to let the player keep playing, while browsing around the rest of the pages. 但是,这样做的想法是让玩家可以继续玩,同时浏览其余页面。

But as soon as the user leaves the page that opened the mainPlayer window, the reference to the mainPlayer window seem to be lost. 但是,一旦用户离开打开mainPlayer窗口的页面,对mainPlayer窗口的引用就会丢失。

How do I, from the site's other pages, check if the mainPlayer window is open and close it on a click event? 如何从网站的其他页面检查mainPlayer窗口是否已打开,并在单击事件时将其关闭?

Thx John 约翰·Thx

Edit 编辑

I checked this thread: Find window previously opened by window.open And did as the answer suggested, with no luck. 我检查了这个线程: 查找以前由window.open打开的窗口 ,并按照建议的答案进行,没有运气。 But perhaps I am misunderstanding the idea. 但是也许我误解了这个主意。

What I did was: 我所做的是:

I created 我建立

function tjek_ClosePlayer()
{
var playerUrl = 'custom_inserts/custom_player.php';
var mainPlayer= window.open('', 'mainPLayer', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=605, height=100') ;
if(mainPLayer.location == 'about:blank' ){ mainPlayer.location = playerUrl ; }
mainPLayer.close();
}

And then called the function, onclick, from the refreshed page. 然后从刷新的页面调用函数onclick。 No luck. 没运气。

Anyone? 任何人?

When you close the parent window, reference to the popup will indeed be destroyed. 当关闭父窗口时,对弹出窗口的引用确实会被破坏。 I guess this is something that cannot be controlled via code. 我猜这是无法通过代码控制的东西。

One thing you can do is write out a cookie when opening the popup, which the popup can check periodically and act upon. 您可以做的一件事是在打开弹出窗口时写出一个cookie,该弹出窗口可以定期检查并采取措施。

For ex: write out a cookie named X='opened' before opening the popup. 例如:打开弹出窗口之前写出一个名为X='opened'的cookie。 In the popup periodically check for the value of X and once it is found to be equal to 'close' , delete the cookie and close the popup window - via window.close() 在弹出窗口中定期检查X的值,一旦发现它等于'close' ,则删除cookie并通过window.close()关闭弹出窗口。

Note: this will be easier if you have the parent page(s) as well as the popup page served from the same domain. 注意:如果您具有从同一域提供的父页面和弹出页面,这将更加容易。

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

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