0

I need create probably an uncommon thing, so I haven't found any guide, and thats why I would like to ask here:

I am creating an interface for a site, which is being created by ajax loading its parts. My web interface can accept an URL parameter as an input. If there is the parameter, my site changes its behavior (loads the page + content by value of that parameter and show it at specified place).

But, at some point, I have to get rid of the parameter. Especially, if someone reloads the page, I want to show the cleanly loaded web page, not the content - but the parameter is still there whie pressing F5

So, my code - which is not working, looks simply like that:

//EDIT: Thanks to @charlietfl. I have here an unload event, which figures in ways like "I want to go to another page by url adress bar" Same problem, jsut need to change it just and only to RELOAD page event.

//we are here: http://example.com/?docId=1  


    $(window).bind('beforeunload',function(){

       //window.location.replace("http://example.com");
         window.location.href = "http://example.com";
 

});

Know two things: 1) $(window).bind works well, with simple alert in it. 2) window.location.replace("http://example.com"); works well too, if fired at some other event, like key press (for my testing)

What I am trying to achieve, is to "skip" the reload by redirecting.

Aaaand one more thing. I know about HTML5 syntax changing the url without reloading the page (change->reload->done), but I can't use it, because of compatibility needed with older browsers.

Well, plase, any tips? Thanks in advance :)

Zorak
  • 709
  • 7
  • 24
  • Sounds like you need to track whatever it is that needs tracking within server session and manage redirects there. You problem description isn't very clear when it is based on `at some point` ... what is that point and what criteria determines it? – charlietfl Oct 18 '15 at 21:29
  • well, hoped, next sentece will make it clear. As I said. I have a parameter in URL. Then, user will try to reload the page. But I need to reload it to its clear state = without url JS parameter. – Zorak Oct 18 '15 at 21:40
  • but using unload event can be triggered numerous ways by user...back button, leaving site etc. There is no way to know what user's next move is. If it is sensitve that they can't reload the url as is you need to use cookies or server sessions to figure it out at server – charlietfl Oct 18 '15 at 21:43
  • there is no "back" in this web app. it always opens in new tab and whole working process with this app is managed by dynamic reloading its own contetnt. I mean, that once you are inside the app, you have no linking to any other pages. Even any sub-pages of that app. – Zorak Oct 18 '15 at 21:56
  • Aaand .. hmm, yes, the only additional problem seems to be in "leaving site" However, I think that this wont be a problem, cause, the app will try to reload and then, browser immediately closes the tab/window. – Zorak Oct 18 '15 at 21:58
  • but user has a back button in browser and they have an address bar they can type into as well as bookmarks ... again it sounds like you need to use session to keep track – charlietfl Oct 18 '15 at 21:59
  • hmm, I havent thing about it like that. Well, still the same problem, just I need to edit my post, really need to catch only the "reload" event. Thank you. – Zorak Oct 18 '15 at 22:04
  • You are still looking at this wrong...it needs to be done at server. There is no way to track users next move when leaving a page using javascript – charlietfl Oct 18 '15 at 22:10
  • [this](http://stackoverflow.com/a/8645928/3465753) might help you – J Santosh Oct 19 '15 at 04:29

0 Answers0