Redirect to external Link in new tab

Hello,

i want to redirect to an external link in a new tab i use : [b]$this->redirect(‘link’, array(‘target’=>’_blank’));

[/b]

the redirection works but not in a new tab can you help me plz

Opening new tab on redirect isn’t related to server. So you can’t force server to open new tab when redirect. Therefore you should control it in your client side. For example you can add target: “_blank” attribute inside the links.

Refer this

Thanks Selvakumar for your reply, i add it inside the link but doesn’t work for me

Hi Tic, this will work


echo Html::a('Link', ['site/about'], ['target'=>'_blank']);

Hi Selvakumar,

thank you again, what i’m looking for is a direct redirection to an external site not a link.

$this->redirect work like a charm but in the same tab …

I’m sorry., But I don’t understand what you are trying to do…

HTTP doesn’t make any assumptions on implementation details of the user interface of clients. It doesn’t even assume that the client has an UI. For this reason, “new tab” or “new window” doesn’t make any sense in the context of a HTTP request/response. That’s why you cannot control it from server side. All you can try is to send the request via AJAX and open the new tab from Javascript but the actual result might depend on the browser and its current configuration.

1 Like

Thank you Phtamas for your answer is very helpfull for me.