How to open a link in new window with laravel?

Member

by adan , in category: PHP Frameworks , 3 months ago

How to open a link in new window with laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elise_daugherty , 3 months ago

@adan 

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:

1
<a href="https://www.example.com" 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:

1
2
3
4
use IlluminateSupportHtml;

$link = Html::link('https://www.example.com', '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.