Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.opener.location.href works in IE but not Chrome or Safari

I have been researching this problem and while there's lots of posts on various forums about similar problems, none of the problems or solutions exactly match mine.

I have an application that has been successfully using the function below to redirect back to the parent window once finished with a popup. Recently I have been investigating compatibility with other browsers (to allow the system to be used via iPad) and have found that there is a problem with this function when using Safari or Chrome.

The parent page is a summary of some databased info, and the user clicks a link to open a window (via window.open) to view more detailed data. When finished there is a link on the child window that refreshes the data on the parent (partly to ensure the correct data is displayed when you return to the parent) and closes the child.

The Console in Safari reports "the result of 'window.opener.location.href' is not a function". I have tried to use the above and 'window.opener.document.location.href' and 'window.opener.window.location.href' (taken from other solutions offered up on the net) but with no success.

I know that some people have this function working well, while others have this sort of problem. I'm wondering if there are any answers to this specific situation.

Here is my function:

function quicklink(url) {
window.opener.document.location.href(url);
self.close();
}

This has worked from day one on IE7,8 and 9 but doesn't work in Safari (for windows or iPad) or Chrome.

Any ideas?

like image 704
Barbs Avatar asked Oct 11 '11 00:10

Barbs


1 Answers

href is a property, not a method. Just assign the URL to it:

window.opener.document.location.href = url;

This will work in IE also. It's a property there too, even if it lets you use it as a method.

like image 111
Guffa Avatar answered Oct 07 '22 18:10

Guffa