How to open a link in new window with laravel?


by adan , in category: PHP Frameworks , 20 days ago

How to open a link in new window with laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elise_daugherty , 19 days ago


To open a link in a new window using Laravel, you can use the target="_blank" attribute in your anchor tag. Here's an example:

<a href="" target="_blank">Click here</a>

In this example, when the user clicks on the link "Click here", it will open the specified URL in a new browser window.

If you are generating links dynamically in your Laravel application, you can use the Html facade to create the link with the target="_blank" attribute. Here's an example:

use IlluminateSupportHtml;

$link = Html::link('', 'Click here', ['target' => '_blank']);
echo $link;

This will generate the same HTML anchor tag with the target="_blank" attribute set.

Remember to always include the target="_blank" attribute responsibly, as opening links in new windows can potentially lead to a poor user experience for some users.