Thursday, May 5, 2011

Redirect/Refresh to fragment identifier

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?

From stackoverflow
  • 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

  • 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.

    Vikram : you could possibly use jquery or any ajax framework to stay on the same page without popping up the address bar. I am doing it that way, so basically i have clubbed some pieces from iUI into iWebkit which makes a deadly combo and gives you much more flexibility as well.
    Vikram : when i say some pieces of iUI, i mean the concept of keeping on the same page rather than popping up address bar and not literally code pieces from iUI. you can work out your own strategy to suit your requirements.

0 comments:

Post a Comment