jquery-address icon indicating copy to clipboard operation
jquery-address copied to clipboard

Path with anchor in non-HTML5 browser after form submit

Open ericbn opened this issue 12 years ago • 1 comments

Hello!

I'm having this issue using IE8 (I wouldn't use IE8, but I just wanted to make sure jquery-address works there too):

An address with an anchor that looks like http://host.com/#/page/#anchor fires the change() event twice, first with /anchor as event.value, then with /page/#anchor. As I'm using the default strict mode, it would distinguish #/anything as an URI, since it has the slash after the hash, and #anything as an anchor, since it has no slash after the hash. Right?

The problem only occurs when I submit a form that's at http://host.com/#/page/ and the address after POST is http://host.com/#/page/#anchor (the anchor pointing to the form). It does not occur when I visit the http://host.com/#/page/#anchor address directly. In this case, the change event is only fired once, with /page/#anchor as event.value, as expected.

Oh, and I'm using jquery-address-1.5, but I saw your commit history and there was no reference to this kind of issues. If you want to test this with the website I'm developing, I can send you the address in private.

Kind regards, Eric

ericbn avatar Apr 11 '13 00:04 ericbn

I got the problem. The form at http://host.com/#/page/ was <form action="http://host.com/page/#anchor" method="post">. Two separate thing were happening:

  1. The form was being submited to http://host.com/page/#anchor, and prior to call to $.address.state('\'), an change() event was being fired with /anchor as event.value.
  2. The URL changed to http://host.com/#/page/#anchor by jquery address, as the state option was set, and then a new change() event was fired with /page/#anchor as event.value.

To avoid this, my solution was not to set the state option for non-HTML browsers using the code below:

if (window.history.pushState) {
    $.address.state('\');
}

ericbn avatar Apr 13 '13 02:04 ericbn