dokgu
dokgu

Reputation: 6030

jQuery Popup to open a new tab in the main browser window

I'm opening a popup window using

window.open(url, title, 'width=1055,height=750,scrollbar=yes');

When clicking something on that popup, I want to close the popup and then redirect the browser tab that opened the popup. I achieve this by doing

window.opener.location.href = 'newurl.php';
window.close();

I'm now adding some validation to check whether the browser tab that opened the popup is still available or if it's been closed. Now I'm doing this:

if(window.opener) {
    window.opener.location.href = 'newurl.php';
    window.close();
} else {
    window.location.href = 'newurl.php';
}

What I want to do now is on the else portion, instead of using the popup window, I'd like to open a new tab on the main browser window. I hope I was clear on what I wanted help with. Let me know if you need more information.

Note

I am aware that using a modal is probably a better approach but this decision is not for me to make.

Upvotes: 0

Views: 1648

Answers (1)

dokgu
dokgu

Reputation: 6030

After some trial and errors I finally got it to work. Here's the changes I made:

if(window.opener) {
    window.opener.location.href = 'newurl.php';
} else {
    window.open('newurl.php', '_blank');
}

window.close();

Upvotes: 1

Related Questions