Forum Moderators: open
I hope someone can give me a clue about why this is happening. I'm no expert in Javascript.
I have this simple code that loads a new page when a button is clicked.
---
function emptybasket() {
document.location='emptybasket.php';
alert("Shopping basket empty!");
}
---
The last alert line was added because Firefox ignores the document.location line without having this line or I guess a similar one.
I.E works fine without the alert line, if anyone has a clue why this is happening please let me know.
Best regards
Benny
Thanks for your suggestion. I just tried it:
Changed the script to this:
---
function emptybasket() {
window.location.href='emptybasket.php';
}
---
As the former it works fine in IE, but not in Firefox?
Adding the following line makes the redirect work.
alert("Now it works...");
But that is highly annoying and I am very interested in knowing what causes this problem?
Further information that I might suspect causing the problem are that the page is located in a frame. And the redirect works if I set the location to the top level.
Best regards
Benny
However, my guess would be that there is some other js code on the page (or other frame) that is interfering somehow.
As an alternative you could use an html link (with an image of a button). This has the advantage that javascript is not required (but I guess other features require it).
If you use a link, consider adding rel="nofollow" to keep search engines out.
Kaled.
Thanks for your suggestions.
I finally managed to find out why it was not working or rather what was causing it not to work.
I had a button with OnClick="emptybasket();" action. within a form.
After changing the <button> to the form element input type="button" it worked?
Remember this worked fine in IE but not in Firefox and I did make several w3 validations on the webpage without getting any errors.
Now if anyone could tell me why Firefox does not permit a <button> within a form when you try to use location within a frame?
Best regards
Benny