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',
  • have you try with , onclick=""this.target=\'_blank\'""? – Rakesh Jesadiya Dec 21 '16 at 10:28
2

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>.

  • I had tried such but it does not work – Zinat Dec 21 '16 at 8:00
  • What does this code generate in frontend? Can you paste it here? Whole element... – Anitr Dec 21 '16 at 8:01
0
$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.

  • It did not work :( – Zinat Dec 21 '16 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 – Keyur Shah Dec 21 '16 at 10:23
  • 1
    Yes, and please remove your duplicate marking in may next question, that's different – Zinat Dec 21 '16 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.