5

Below codes opens the link in same window, how can I change it to open it in new tab?

if ($canModify) {
 $data = [
 'label' => __('Login As Customer'),
 'class' => 'login login-button',
 'on_click' => 'window.open( \'' . $this->getInvalidateTokenUrl() .
 '\')',
 'sort_order' => 70,
 ];
 }

edit:

below are not working:

'on_click' => 'window.open( \'' . $this->getInvalidateTokenUrl() .
 '\',\'_blank\')',

and

'on_click' => 'window.open( \'' . $this->getInvalidateTokenUrl() .
 '\')',
 'target' => '_blank',
asked Dec 21, 2016 at 7:46
1
  • have you try with , onclick=""this.target=\'_blank\'""? Commented Dec 21, 2016 at 10:28

2 Answers 2

3

You should add attribute target="_blank" to your element. Something like this I think would work:

if ($canModify) {
 $data = [
 'label' => __('Login As Customer'),
 'class' => 'login login-button',
 'on_click' => 'window.open( \'' . $this->getInvalidateTokenUrl() .
 '\')',
 'sort_order' => 70,
 'target' => '_blank' 
 ];
 }

For example: <div class="login login-button" onclick="window.open('http://www.google.com')" target="_blank">Click me</div>.

answered Dec 21, 2016 at 7:55
2
  • I had tried such but it does not work Commented Dec 21, 2016 at 8:00
  • What does this code generate in frontend? Can you paste it here? Whole element... Commented Dec 21, 2016 at 8:01
3
$this->addButton(
 'back', [
 'label' => __('New Tab'),
 'onclick' => 'window.open(\'' . $this->getTabUrl() . '\',\'_blank\')',
 'class' => 'back'
 ], -1
 );

This is working fine in my system. If it's still create an issue then you should at least check in other browser.

answered Dec 21, 2016 at 9:57
3
  • It did not work :( Commented Dec 21, 2016 at 10:21
  • Have you tried in another browser ? Because it's working fine in 2 different system. So I think there must be browser issue or you done some typo mistake :) @Zinat Commented Dec 21, 2016 at 10:23
  • 1
    Yes, and please remove your duplicate marking in may next question, that's different Commented Dec 21, 2016 at 10:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.