Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

setting window.location in javascript doesn't work unless i have an alert

  • 2 个回答
  • 3 人有此问题
  • 7 次查看
  • 最后回复者为 AnonymousUser

more options

I am attempting to jump to a new URL from a string that I've patched together in javascript. If I just use window.location = newurlstring firefox just reloads my current page. But it I put an alert after i set the new location, then it jumps. I have a very stripped down version of what I'm trying to do at http://www.secretarea51.com/Searches/search2.htm That page has two buttons. Both call the same javascript function but with different parameters. One does an alert after attempting to set the new location, the other bypasses the alert. If the alert is bypassed, all that happens is the current page gets reloaded. If the alert is not bypassed, then the new page does get loaded. You can look at the source for the page. I've stripped it down to about the bare minimum that I could to demonstrate the problem I'm having. I'm sort of new to javascript, but as best as I can tell, there shouldn't be a difference between the two situations.

This happened

Every time Firefox opened

== ever since I've tried it

I am attempting to jump to a new URL from a string that I've patched together in javascript. If I just use window.location = newurlstring firefox just reloads my current page. But it I put an alert after i set the new location, then it jumps. I have a very stripped down version of what I'm trying to do at http://www.secretarea51.com/Searches/search2.htm That page has two buttons. Both call the same javascript function but with different parameters. One does an alert after attempting to set the new location, the other bypasses the alert. If the alert is bypassed, all that happens is the current page gets reloaded. If the alert is not bypassed, then the new page does get loaded. You can look at the source for the page. I've stripped it down to about the bare minimum that I could to demonstrate the problem I'm having. I'm sort of new to javascript, but as best as I can tell, there shouldn't be a difference between the two situations. == This happened == Every time Firefox opened == ever since I've tried it

所有回复 (2)

more options

Hmmm... It would seem as though the problem has to do with the type="submit" that I had in the input tags for the buttons. I took that out and now it does the jump with or without the alert.

Now I've just got to find out how to make it look like a button without the type="submit" in there. But I can do that part.

You can scratch this from the bug list or whatever this is. Maybe shift it to an oddities list or something because I still don't know why the original behavior would be different whether there's an alert or not.

more options

I think you can only have one type="submit" per form. To understand it better, instead of using the onclick="doSearch(1);" attribute on the input element, use the action="javascript:doSearch(1);" attribute on the form element. So it's one submit action per form.