如何使用 URL 字符串在单独的 _blank
窗口中打开搜索页面的搜索词?现在它可以工作,但只能作为 _self 目标,而不是在新窗口中作为 _blank。
我需要它在空白的新窗口中显示结果。
JavaScript:
<script language="JavaScript">
function GoToURL()
{
var URLis;
URLis = document.URLframe.u.value
{
var location=("https://SearchMyPageA.com/?q=" + URLis + "&ia=meanings");
this.location.href = location;
}
}
</script>
HTML:
<form name="URLframe" method="post">
<input value="test" type="text" name="u" size="70">
<input type="button" onclick="GoToURL(this)" value=" Search ">
</form>
注意:我宁愿想要一个 JavaScript 答案,但如果没有 JavaScript 答案,那么我想查询答案也可以。
最酷的部分:这是这段代码最酷的部分。这适用于互联网上的几乎所有搜索机,只需对值和 JavaScript 进行一些调整,以适应我们使用的搜索框的数量。您唯一需要做的就是在原始页面上输入 test 并查看 URL 在该页面上的外观,然后将 URL 地址和结束文本替换为 + URLis +
代表您想要的内容在搜索框中键入而不是测试
最佳答案
无法使用位置来打开新窗口。尝试使用 window.open()
并使用 _blank
作为第二个参数。
function GoToURL()
{
var URLis;
URLis = document.URLframe.u.value
{
var location=("https://SearchMyPageA.com/?q=" + URLis + "&ia=meanings");
//this.location.href = location;
window.open(location, '_blank')
}
}
<form name="URLframe" id="form" method="post">
<input value="test" type="text" name="u" size="70">
<input type="button" onclick="GoToURL(this)" value=" Search ">
</form>
关于javascript - 如何使这个URL框搜索机目标在一个新的_blank窗口中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43600598/