2013-03-14 24 views
0

打開一個URL +元素值我有這樣的代碼:在同一幀

<form> 
    <input type="text" placeholder="Enter something..." id="box"> 
    <button onclick="window.open('http://example.com/' + document.getElementById('box').value);">GO 
    </button> 
</form> 

當用戶輸入一個單詞,點擊「GO」,他去一個URL +輸入的值。使用此代碼,該頁面會在新窗口中打開,但我想在同一個框架中打開它。我該怎麼做?

+1

框架爲''_self''或''window.location的刷新當前頁面''。你的選擇! – 2013-03-14 13:56:13

回答

1

嘗試用以下

window.open('http://example.com/' + document.getElementById('box').value,'_self') 

所以,你的代碼會像添加此

<form> 
    <input type="text" placeholder="Enter something..." id="box"> 
    <button onclick="window.open('http://example.com/' + document.getElementById('box').value, '_self');">GO 
    </button> 
</form> 
+0

迄今爲止最好的解釋 - 可以補充一點,'_self'專門針對你所在的窗口。您可以在https://developer.mozilla.org/en/docs/DOM/window.open中找到更多信息,這些信息實際上會顯示一些您可以指定可以派上用場的簡潔選項。 – 2013-03-14 14:14:46

2
window.open ('page2.htm','_self',false) 
0

您可以使用javascript。

window.location = url + text;