Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a website that has been up and running for years. Suddenly, the javascript to return to the page opener does not function. Here is the javascript.
OnClientClick="window.opener.location.reload(false);window.close()" 


Maybe something has changed?

It works OK with Chrome. But not Firefox.

What I have tried:

I replaced reload(false) with href. No change.
Posted
Updated 11-Jun-23 16:41pm
v2

1 solution

Quote:
A Window-like object referring to the window that opened the current window (using window.open(), or by a link with target attribute set). If this window was not opened by being linked to or created by another, returns null.

Referenece: Window: opener property - Web APIs | MDN[^]

Believe, in your case:
Quote:
Windows opened because of links with a target of _blank don't get an opener, unless explicitly requested with rel=opener

So, put rel=opener to the tag while opening the window and then it should work fine.
 
Share this answer
 
Comments
BobbyStrain 12-Jun-23 17:46pm    
Thank you. It works as intended. I have another link on the child page to return to the parent, but leave the child open.
"window.open('', 'parent');parent.focus"
However, focus remains on the child. Which requires the user to click the parent tab to focus. I can't find any script to achieve this. Any suggestion?
Sandeep Mewara 12-Jun-23 22:28pm    
I will try to find any control on the parent page and set focus on it.
BobbyStrain 13-Jun-23 13:06pm    
I don't understand your suggestion. This look like code-behind, not JavaScript. JavaScript worked for years, but works no more. Maybe you can provide a bit more code?
Sandeep Mewara 14-Jun-23 0:35am    
You can find any control on the parent page using Javascript and then explicitly try to set focus there.
Believe this article will provide some reference: https://www.codeproject.com/Articles/29617/Partial-update-of-parent-page-via-AJAX-ASP-NET-2-0
BobbyStrain 15-Jun-23 16:23pm    
I looked at your article. That is much more complex than the previous javascript.

OnClientClick="window.opener.location.reload(true)".

This script will leave the child open with focus. I can select the parent page and it responds properly. There must be some magic to set focus on the parent through some simple javascript.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900