中心window.open在表单提交

编程入门 行业动态 更新时间:2024-10-28 08:17:06
本文介绍了中心window.open在表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的代码如下所示:

<script type="text/javascript"> function directions(sacred) { var x = screen.width / 2 - 700 / 2; var y = screen.height / 2 - 450 / 2; window.open(sacred.action, 'Directions', 'height=485,width=700,left=' + x + ',top=' + y); return false; } </script> <form action="maps.google/maps" method="get" target="Directions" onsubmit="return directions(sacred);">

我不懂js,所以如果看起来很草率,请放轻松。

I don't understand js, so take it easy on me if it looks sloppy.

我可以让它工作正常:

<form action="maps.google/maps" method="get" target="Directions" onsubmit="Directions=window.open('about:blank','Directions','width=600,height=400');">

一旦我尝试将 onsubmit 连接到上面的剧本,我迷路了。我甚至都不知道上述功能是否可靠。

Once I try to connect the onsubmit to the above script, I get lost. I don't even know if the above function is reliable.

我在这里打开引擎盖: jsFiddle

I have popped open the hood here: jsFiddle

问题是表单提交到新选项卡,并忽略 window.open 一起。

The problem there is the form submits into a new tab, and ignores window.open altogether.

提前感谢您的帮助。

推荐答案

试试这个: jsfiddle/333Qy/ 1 /

<script> function directions(sacred) { var x = screen.width / 2 - 700 / 2; var y = screen.height / 2 - 450 / 2; console.info(sacred); window.open(sacred.action, 'Directions', 'height=485,width=700,left=' + x + ',top=' + y); return false; } </script> <p> <form action="maps.google/maps" method="get" target="Directions" onsubmit="directions(this);"> <input class="directions-input" id="saddr" name="saddr" type="text" placeholder="enter zip-code" value="enter zip-code" onfocus="this.value = this.value=='enter zip-code'?'':this.value;" onblur="this.value = this.value==''?'enter zip-code':this.value;" /> <input type="submit" class="directions-submit" /> <input type="hidden" name="daddr" value="210+East+Northampton+Street,+Bath,+PA" /> <input type="hidden" name="hl" value="en" /> </form> </p>

onsubmit应该是函数调用。此外,神圣是不确定的。我在上面的代码

onsubmit should be a function call. Also, sacred is undefined. I have made the changes in the above code

更多推荐

中心window.open在表单提交

本文发布于:2023-08-06 02:11:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1309443.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   中心   window   open

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!