Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel redirect to a new tab

I need to open a new URL after a post request. I have done this at the end of my controller.

Redirect::away($url)

The above calls works perfect, however, I want to open the URL in a new tab.

I tried to, away, and intended methods that are there in the laravel doc. None work as intended.

like image 909
pixelscreen Avatar asked Nov 25 '15 10:11

pixelscreen


People also ask

How to open url in new tab in Laravel?

Laravel or (PHP in general) is a server side and we cannot open a new tab in them, because the new tab is browser thing so the solution is to do it in front side like: using <a> TAG <a href="#Link" target="_blank">New tab</a> . using popup javascript window.


2 Answers

Redirect::away() or Redirect:to() both are server side commands and all they do is to redirect to a url with a slight difference as mentioned in this thread

As, both are server side commands they cannot open a new tab.

You need client side code to open new tab, for example: <a href="#" target="_blank">Open in a new tab</a>

like image 179
Zahan Safallwa Avatar answered Oct 13 '22 14:10

Zahan Safallwa


I know this is an old question, but for reference you can cause a client redirect to a new window/tab from the server using

echo "<script>window.open('".$url."', '_blank')</script>";

As a side note, whether this opens the link a new window or new tab is dependent on the browser and browser settings.

like image 6
rareclass Avatar answered Oct 13 '22 12:10

rareclass