首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript windows.location,跳过

Javascript windows.location,跳过
EN

Stack Overflow用户
提问于 2011-11-20 05:30:16
回答 1查看 300关注 0票数 0

我遇到了一个奇怪的问题,外部javascript文件函数跳过了windows.location。我的程序应该从表单中接收信息,然后创建、验证它,并在验证后使用get将其发送到一个php文件。

我简化了我的代码,如下所示

代码语言:javascript
复制
function validation(){
 var alerting;//receives from forms commented out
alerting="";
var url="phpadd.php";//after this i would validate it and create the alert but all of that is commented out and irrelevant
if(alerting==""||alerting==null)
   {
   windows.location=url;
   }
   else
   {
   alert(alerting);
   }
}

但它并没有起作用。

这是真正有趣的事情,当我在windows.location调用php文件之后在结尾添加了一个警告。当我不这样做的时候,它就不会。例如

代码语言:javascript
复制
function validation(){
 var alerting;//receives from forms commented out
alerting="";
var url="phpadd.php";//after this i would validate it and create the alert but all of that is commented out and irrelevant
if(alerting==""||alerting==null)
   {//I also create the code here to put values In the url but I commented them all out so this is my effective code.
   windows.location=url;
   alert(url);
   }
   else
   {
   alert(alerting);
   }
}

工作,但它必须先打印出警报。另一方面,当我在windows.location调用之后没有提示时,它根本不起作用。(我知道它和提示一起起作用,因为它会被重定向到php文件,我知道这个文件也是有效的)。

它不一定是警示的(Url),也可以是警示任何东西。事实上,它确实在后来的while(1)循环中工作,但几乎首先使浏览器崩溃。这就像它在做它应该做的事情之前离开了函数,并忘记了它。

我已经在firefox和google chrome中尝试过了,但这两种方法都不起作用。

还有,如果你找不到这样做的方法。如果你能给我一种方法,把表单中的值输入到javascript中,然后将有效的值发送到一个没有windows.location的php文件中(我已经尝试了我找到的所有其他变体,比如: windows.location.href location.href location.assign(url)),我将不胜感激。

顺便说一句,我省略的代码不会导致问题,因为它被注释掉了它不工作的地方,而在它工作的地方,它是不相关的,因为它工作,它只是发出了一个我不想要的警告。

EN

回答 1

Stack Overflow用户

发布于 2011-11-20 05:32:28

你应该打电话给我

代码语言:javascript
复制
window.location = url;

代码语言:javascript
复制
windows.location = url;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8197505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档