提交表单的可能性(左-/中-/在新选项卡或窗口中打开-)单击html链接
Possibilities of submit a form on (left-/middle-/open-in-new-tab-or-window-)clicking an html link
使用jQuery,我想在单击html链接时提交POST表单,进入打开链接的目标浏览器选项卡。
这是
<a id="submit_button" href=".">Search for values</a>
<script>
$('#submit_button').click(function() {
$('#my_form').submit();
return false;
});
</script>
如果用鼠标单击链接,则根据需要提交表单。但是
- 如果单击中间的按钮打开新选项卡中的链接,我希望看到在该新选项卡中提交的表单
- 如果单击右键并从菜单中选择"在新选项卡中打开链接"或"在新窗口中打开链接",我希望看到表单以所选方式提交
如何实现这一点有什么想法或建议吗?
$('#submit_button').click(function(e) {
$(this).attr("href", "javascript:void(0)"); //reset by every click.
$('#my_form').removeAttr("target"); //reset
if (e.button == 1) //middle mouse button
{
e.preventDefault(); //stop the default behavior of the middle mouse button
$('#my_form').attr("target", "new_window");
}
$('#my_form').submit();
return false;
});
你可以在鼠标中键上尝试这个代码,在新的选项卡变体中打开你可以这样做。它真的很脏,脏得很好!
$('#submit_button').contextmenu(function(e) {
window.onbeforeunload = function() {
//You do want to check here if the unload came from the right source
localStorage.setItem(name, $('#your_inputs').val());
//save your form data to local storage
}
$(this).attr("href", location.href);
//set the link to reload itself
$('#my_form').attr("target", "new_window");
//set the target to a new window
});
//put this by default on your page, when it detect local storage submit.
window.onload = function() {
var name = localStorage.getItem(name);
if (name !== null)
{
//repopulate the form and send to server using normal post
//delete the local storage items after this.
}
}
相关文章:
- 窗口大小html css
- 如何关闭html中的iframe弹出窗口
- javascript弹出窗口没有正确加载html表单
- 按下一个HTML按钮,该按钮使用一个功能在同一个新窗口中打开URL
- 从html锚元素传递窗口对象
- 编辑弹出窗口的HTML的单击命令
- Chrome应用程序在全屏中创建新窗口-html元素不是全高的
- 基本html页面和弹出窗口之间的数据交换
- 使用html中的jquery输入值窗口提示
- Chrome扩展-在全屏视频顶部显示自定义通知/弹出窗口(HTML元素)
- Chrome扩展程序弹出窗口.html很慢,打开不快?1.89KB 页面为 5 秒
- 将画布上下文插入到动态创建的新窗口 html 中的 html 字符串
- Chrome扩展程序更改弹出窗口.html文本
- 如何用参数和php滑动弹出窗口(html)
- 在弹出窗口.html从后台.js的Onclicked事件
- 阻止 Chrome 扩展程序的弹出窗口.html自行打开
- Chrome 扩展程序页面弹出窗口.html不会调整大小
- Chrome 扩展程序:弹出式窗口.html会在新标签页中关闭并打开响应
- 将请求从弹出窗口.html发送到侦听器.js
- 在 visjs 中右键单击节点(上下文菜单)时打开扩展弹出窗口(html 列表)