Cari Bantuan

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Pelajari Lebih Lanjut

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

  • 2 balas
  • 3 memiliki masalah ini
  • 4 kunjungan
  • Balasan terakhir oleh 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

Semua Balasan (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.