Reputation: 219
I'm calling the script below on a button onclick, where .value is a URL dependent on a drop down section. I want the resulting URL to open in a new window ('_blank') when the button is clicked. How can I modify this code to do that? Any help is appreciated.
function openResultsPage() {
if(document.getElementById('selectedRace').value){
window.location.href = document.getElementById('selectedRace').value;
}
}
Upvotes: 1
Views: 4331
Reputation: 23208
You should use window.open to open a new window
NOTE: I am using height and width in third parameter to make sure that window.open open new window instead of new tab
function openResultsPage() {
if(document.getElementById('selectedRace').value) {
window.open(document.getElementById('selectedRace').value,'','width=700, height=500');
}
}
Upvotes: 1
Reputation: 4339
You can try this:
function openResultsPage() {
if(document.getElementById('selectedRace').value){
var href = document.getElementById('selectedRace').value
window.open(href,'_blank').value;
}
}
Upvotes: 2