如何使用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答案,那么我猜的查询答案也会有效。
COOL部分:这是此代码的很酷的部分。这适用于互联网上的几乎所有搜索机器,在值和JavaScript中稍微调整以适应我们使用的搜索框的数量。您唯一需要的是在原始页面上键入test并查看URL在该页面上的显示方式,然后替换单词URL地址和结束文本,+ URLis +
表示您在搜索框中键入的内容而不是测试
答案 0 :(得分:1)
无法使用位置打开新窗口。请尝试使用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>
答案 1 :(得分:0)
尝试使用...
window.open(
'https://SearchMyPageA.com/?q=' + URLis + '&ia=meanings',
'_blank' // <- This is what makes it open in a new window.
);