laravel 重定向到新标签页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33913461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
laravel redirect to a new tab
提问by pixelscreen
I need to open a new URL after a post request. I have done this at the end of my controller.
我需要在发布请求后打开一个新 URL。我已经在我的控制器的最后完成了这个。
Redirect::away($url)
The above calls works perfect, however, I want to open the URL in a new tab.
上面的调用很完美,但是,我想在新选项卡中打开 URL。
I tried to, away, and intended methods that are there in the laravel doc. None work as intended.
我尝试使用 laravel 文档中的方法。没有一个按预期工作。
回答by Zahan Safallwa
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
Redirect::away()
或者Redirect:to()
两者都是服务器端命令,它们所做的只是重定向到一个与此线程中提到的略有不同的 url
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>
您需要客户端代码才能打开新选项卡,例如:
<a href="#" target="_blank">Open in a new tab</a>
回答by rareclass
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.
附带说明一下,这是否会在新窗口或新选项卡中打开链接取决于浏览器和浏览器设置。