clestcruz
clestcruz

Reputation: 1111

Open a new tab using inline javascript

Is there a way I can open a new tab using inline javascript for the twitter tweet box. I tried placing target="_blank" using inline javascript but it doesn't seem to work.

<a id="twitter" onclick ="window.location.href='https://twitter.com/intent/tweet?text=Electric Studio Referral Code: ' + document.getElementById('input-refcode').value + ' https://www.electricstudio.ph/' "  target="_blank"></a>

Upvotes: 0

Views: 1823

Answers (1)

Zohaib Ijaz
Zohaib Ijaz

Reputation: 22885

Use the target="_blank" attribute in the anchor tag

<a href="your_url" target="_blank">Your Text</a>

And if you url is dynamic as in your case, call a funciton on click action and then using javascript, open a new tab.

<a onClick="openTab()>Your Text</a>

function openTab(url) {
   var url = 'https://twitter.com/intent/tweet?text=Electric Studio Referral Code: ' + document.getElementById('input-refcode').value + ' https://www.electricstudio.ph/';
   var win = window.open(url, '_blank');
   win.focus();
}

Upvotes: 1

Related Questions