但它显示在主窗口中。单击“提交”按钮时,有没有办法在新窗口中打开?
<script type="text/javascript">
function search_navigate() {
var obj = document.getElementById("navbar_search");
var keyword = obj.value;
var dst = "http://smite.guru/stats/" + keyword;
window.location = dst;
}
</script>
<span id="navbar_form">
<input type="search" placeholder="Search Articles..." id="navbar_search" />
<input type="button" id="navbar_submit" value="Submit" onClick="search_navigate()" />
</span>
答案 0 :(得分:3)
使用window.open()
代替window.location
Details
将资源加载到新的浏览上下文(例如窗口) 或者已经存在的,具体取决于指定的参数。
window.open(dst);
答案 1 :(得分:0)
试试这个
function search_navigate() {
var obj = document.getElementById("navbar_search");
var keyword = obj.value;
var dst = "http://smite.guru/stats/" + keyword;
window.open(dst);
}
&#13;
<span id="navbar_form">
<input type="search" placeholder="Search Articles..." id="navbar_search" />
<input type="button" id="navbar_submit" value="Submit" onClick="search_navigate()" />
</span>
&#13;
答案 2 :(得分:0)
window.open(dst)
这将是在新窗口中打开链接的最佳选择。
答案 3 :(得分:0)
window.open(dst,"_blank");
在新窗口中打开它