Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path with anchor in non-HTML5 browser after form submit #173

Open
ericbn opened this issue Apr 11, 2013 · 1 comment
Open

Path with anchor in non-HTML5 browser after form submit #173

ericbn opened this issue Apr 11, 2013 · 1 comment

Comments

@ericbn
Copy link

ericbn commented Apr 11, 2013

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
Copy link
Author

ericbn commented Apr 13, 2013

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('\');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant