I'm trying to make it so that my button will open a url in a new tab.
I can get it to work using window.location.href, but the url doesn't open in a new tab that way.
I'm using jQuery and Javascript, and the code itself is inside of a larger jQuery function.
$('#code').click(function(){
window.location.href = 'http://www.example.com'
});
The button has no href attribute on page load.
<button id="code" type="submit" class="btn btn-success" style="width:400px;"><span class="glyphicon glyphicon-download"></span> Generate Code</button>
I've tried using .attr and .prop though it hasn't worked either. I'm kinda new to this stuff so I could've just done something wrong.
I'm open to either adding an href to the button or using the .click function or whatever, I just need to get this to open to a new tab.
Edit:: Ok, more explanation.
On Page load, the button onclick starts a timer that increments a progressbar. After the progressbar is done I want the button to open a link.
This will open the url in a new window:
$('#code').click(function(){
window.open("http://www.w3schools.com");
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments