Redirect/Refresh to fragment identifier

3.5k Views Asked by At

Im using the iUI framework to create a site. If your not familiar with this you have one page made up of divs and you navagate the user between with fragment identifiers.

The problem with this is if your user adds content it is not visible until they refresh. In my sistuation they add data to a list via jquery post but like I say they see nothing until a refresh and once you do a refresh it goes to the parent div as the #fragment has been lost.

So I have managed to get the page to go to mywebsite.com/#_fragment after the update using window.location = mywebsite.com/#_fragment but it doesn't actually reload the page.

Anyone have any clues has how to refresh a page to a fragment?

2

There are 2 best solutions below

3
On

I believe you would be using iUI to build iPhone friendly web-app. I am not sure if you have already evaluated iWebkit for the same or not. I looked at iUI and iWebkit both and found iWebkit to be much more featured, stable & easy to implement as well.

0
On

URI fragment identifiers are client-side only, and are not sent over to the server, i.e., if you inspect the HTTP request header, you will not see #_fragment. Additionally, making changes to the URI that only modify the fragment will not trigger any DOM events.

While there are workarounds like using a setInterval() call to actively monitor the document.location.hash property, the easiest thing is to simply change the query string arg. For example, instead of:

window.location = mywebsite.com/#_fragment

include a query string component like:

window.location = mywebsite.com/?refresh=1#_fragment

The presence of the "?refresh=1" (or any other key/value pair) will cause the browser to make a request to the server, while preserving the #hash identifier.

See here for more info about the JS location object: http://docs.sun.com/source/816-6408-10/location.htm