2012-10-14 169 views
1

我在按鈕onclick上調用以下腳本,其中.value是依賴於下拉部分的URL。我希望在單擊按鈕時在新窗口中打開生成的URL('_blank')。我怎樣才能修改這個代碼來做到這一點?任何幫助表示讚賞。表單按鈕打開新頁面onclick

function openResultsPage() { 
    if(document.getElementById('selectedRace').value){ 
          window.location.href = document.getElementById('selectedRace').value; 
         } 
        } 
+0

新的窗戶可以打開v ia'window.open(uri,window_name [,settings]);'https://developer.mozilla.org/en/docs/DOM/window.open – Niko

回答

2

你可以試試這個:

function openResultsPage() { 
    if(document.getElementById('selectedRace').value){ 
    var href = document.getElementById('selectedRace').value 
    window.open(href,'_blank').value; 
    } 
} 
+0

這工作完美。謝謝! – trobbins26

0

你可以試試這個。

<head> 
<base target="_blank"> 
</head> 
1

您應該使用window.open打開一個新窗口

注:我使用的高度和寬度在第三個參數,以確保window.open打開了新的窗口,而不是新的標籤

function openResultsPage() { 
    if(document.getElementById('selectedRace').value) { 
     window.open(document.getElementById('selectedRace').value,'','width=700, height=500'); 
    } 
} 
+0

Im sorry for the confusion。一個新標籤是我想要的。 – trobbins26