打开表单会出现新窗口
Opening form result in new window
我有一个表单,有两个按钮提交。
代码是:
<form action="index.php" method="get">
<table cellpadding="2" cellspacing="3">
<tr>
<td><input type="text" name="q" size="20" /></td>
</tr>
<tr>
<td>
<input type="submit" name="site" value="site search" class="submit" />
<input type="submit" name="google" value="google search" class="submit" />
</td>
</tr>
</table>
</form>
我想要的是,如果你按下按钮,谷歌结果将在一个新的窗口打开。
<form action="http://www.google.com/search" method="get" target="_blank">
在index.php中,您可以根据按下的按钮执行单独的函数。例如:
<?php
if(isset($_GET('google'))&&isset($_GET('q'))){
header('Location: http://www.google.ca/search?q=' . $_GET('q'));
}
if(isset($_GET('site'))&&isset($_GET('q'))){
//function here
}
?>
您确实可以通过javascript实现:
<script type="text/javascript">
function OpenGoogleSearch() {
var q = document.getElementById("google").value;
window.open("http://google.com/search?q=" + q);
}
</script>
这需要稍微改变一下形式:
<form action="index.php" method="get">
<input id="google" type="text" name="q" size="20" /></td>
<input type="submit" name="site" value="site search" class="submit" />
<input type="button" name="google" value="google search" class="submit" onclick="OpenGoogleSearch()" />
</form>
javascript使用文本字段的id(您应该添加)来获取输入的值。与提交不同,google搜索使用了一个带有onclick属性的普通按钮,该按钮调用javascript函数。
注意,这只会在一个新窗口中打开google搜索;如果你想在一个新窗口中打开"站点搜索",你应该添加target="_blank"
,就像Neal说的。
相关文章:
- 防止Iframe窗体在新窗口中打开
- 在新窗口上使用d3.js
- 按下一个HTML按钮,该按钮使用一个功能在同一个新窗口中打开URL
- asp.net MVC,重定向到视图,视图打开新窗口到外部url,它'It’’’’我们被当成一种风景
- 如何在新选项卡中而不是在新窗口中打开URL
- 如何禁用鼠标中键单击超链接以在新选项卡或新窗口中打开
- 如何打开一个新窗口或选项卡,并将其提供给javascript执行
- window.open:是否可以通过修改DOM来打开一个新窗口
- Chrome应用程序在全屏中创建新窗口-html元素不是全高的
- 如何在windowsphone 7浏览器中通过javascript打开新窗口或选项卡
- 为在新窗口中打开外部链接创建异常
- 如何使用base64 PDF内容打开新窗口
- 在后台打开新窗口
- 在新窗口中通过谷歌地图的localStorage作为地图中心
- javascript window.open(),并在新窗口中搜索DOM
- 打开一个新窗口并更改其父窗口'的内容
- 在Firefox restartless插件中,当一个新窗口打开时,我如何运行代码(监听窗口打开)
- SVG编辑链接获胜't在新窗口中打开
- 如何通过单击数据在新窗口上显示TableView数据
- 打开新窗口进行打印时不显示 JavaScript 图像