Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting to a new tab in PHP

Tags:

javascript

php

I have seen this question being asked many times here, but I couldn't get an answer that works!

i am trying to redirect to a load.php TO A NEW TAB using the following script:

echo '<script>window.open("load.php","_blank)</script>';

for some reason it is not working and it stays on the same page.

i am using chrome!

is there any possible way to redirect to a new tab? thanks a lot

like image 556
Ashraf D. Milhim Avatar asked Jul 03 '17 23:07

Ashraf D. Milhim


1 Answers

Most browsers will block window.open unless it is a result of a direct user interaction i.e. the onclick event handle of an anchor tag being fired.

There are ways you can try and "trick" popup blockers, but it is unreliable and considered bad practice. If a user has chosen to enable a popup blocker, it should be respected.

What I would suggest is to also add a link on your page along the lines of the following:

<a href="load.php" target="_blank">Click here</a> if the window does not open in a seperate window.

This would ensure that the user can still open the window manually should it be supressed by a popup blocker.

like image 139
James Avatar answered Oct 20 '22 18:10

James