czwartek, 23 października 2008

Safari: submit, back, submit... oops!

I was building a frond-end for a file transferring application. One of numerous browser bugs I've found was particularly interesting....

Hi!

I came across an interesting bug. I described it in an article: Safari: submit, back, submit, oops!

In a nutshell... say you have a form containing a hidden field. Its value is dynamic, e.g. random number printed by PHP. You submit the form, press back button in Safari. The HTML is generated again with a new value, Safari displays this new html (not cached version!)... but new value of this hidden field is ignored and in memory has old value. So if you submit the form again, new values of visible fields are submitted, and old value of hidden field. Phew.

Example

I isolated the problem and prepared a minimal illustration:
demonstration

and the code.

Steps

Environment: Windows XP, Safari 3.1.2 (525.21)

When you visit the site, PHP generates unique value of $VARIABLE. Then it prints it out as text and then again in value of a hidden field. Then JavaScript comes into action. It takes the value of a hidden field and displays it as alert pop-up.

Intuitively, both values (the printed one and the one in JS pop-up) should be the same, and this is the case when you visit the document.

You then submit the form - it submits to server.php file which displays correct value. So far so good.

You then press back button in Safari. This step is important - if you go back to first address other way, the bug won't show up.

And this time you see new printed value. But JS alert contains previous value! You can preview HTML - input tag contains new value. But if you submit the form, old value goes to the server.

And on Mac?


I've got only Windows at hand. Could you confirm if the bug exists in Mac version as well?

1 komentarz:

  1. 40 years old Graphic Designer Elise Chewter, hailing from Lakefield enjoys watching movies like Demons 2 (Dèmoni 2... l'incubo ritorna) and Scuba diving. Took a trip to Gusuku Sites and Related Properties of the Kingdom of Ryukyu and drives a Ram. Nazwa domeny

    OdpowiedzUsuń