safari / chrome onsubmit =“location.reload(true)”不工作 [英] safari/chrome onsubmit="location.reload(true)" not working

查看:222
本文介绍了safari / chrome onsubmit =“location.reload(true)”不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上的表单在Safari / Chrome中无法正常运行。当用户提交表单时,会打开一个新选项卡,但我希望原始页面(包含表单的页面)可以重新加载。它适用于IE,Opera和Firefox。



代码:

 < form action =/ search.phpmethod =postonsubmit =location.reload(true)target =_ blankname =myform> 

我尝试了其他的JavaScript函数,如:


  • window.location.reload();
  • document.location.reload();
  • window.location。替换('http://www.websiteurl.com');

  • window.location.href ='http://www.websiteurl.com';

  • 以及其他变体。



我想也许是onsubmit =不起作用,但是当我尝试onsubmit =alert('test')在Safari / Chrome中正常工作。

另外,在表单发布到的search.php页面上if用户使用url直接进入页面,并且不提交表单,我已经设置了body标签将加载为:

 < body onload =window.location.replace(http://www.websiteurl.com)> 

适用于包含Safari / Chrome的所有浏览器。



这里发生了什么?!?!



谢谢!



使用 setTimeout $ c>有时可以通过推迟执行很短的时间来作为一个hacky解决方案: http://jsfiddle.net/xzanQ/


A form on my website is not functioning correctly in Safari/Chrome. When a user submits the form, it opens up a new tab, but I want the original page (page with the form on it) to reload. It works in IE, Opera, and Firefox.

The Code:

<form action="/search.php" method="post" onsubmit="location.reload(true)" target="_blank" name="myform">

I tried other javascript functions like:

  • window.location.reload();
  • document.location.reload();
  • window.location.replace('http://www.websiteurl.com');
  • window.location.href='http://www.websiteurl.com';
  • And other variations of these.

I thought maybe it was the onsubmit="" not working, but when I tried onsubmit="alert('test')" that worked fine in both Safari/Chrome.

Also, on the search.php page that the form posts to, if a user goes directly to the page using the url, and not submitting the form, I have it set that the body tag will load as:

<body onload="window.location.replace("http://www.websiteurl.com")>

which works on all browsers includeing Safari/Chrome.

What is going on here?!?!

Thanks!

解决方案

Since it was the solution for you:

Using setTimeout sometimes works as a hacky solution by postponing execution for a very short time: http://jsfiddle.net/xzanQ/.

这篇关于safari / chrome onsubmit =“location.reload(true)”不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆