Where am I navigating to at the onUnload event?

05-21-06, 04:33 PM
|
|
Newbie Coder
|
|
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Where am I navigating to at the onUnload event?
Can I know at the onUnload event where am I navigating to? The window.location.href points still to the page being displayed and not to the next one.
Thanks!
|

05-21-06, 04:36 PM
|
|
Community VIP
|
|
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm not sure what you mean.
window.location.href will always point to the current page being viewed in that window.
If you set window.location or window.location.href to something else, the page in that window will reload (after firing the onunload event) and the window.location.href will be set to the new page.
|

05-22-06, 06:56 AM
|
|
Newbie Coder
|
|
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Web page filter
Hi TwoD! Thanks for your reply! Maybe I didn't sound clear on my post. The thing is I want to know if there is any function that knows, at the onUnload event, where the user is navigating to. But as you said, I won't get nothing looking after window.location, right? So I will state here exactly what I want and hope you pros could help me on this.
I want a client-side solution for a web page filter. It would act like a java filter, but not on the server-side. I need this filter so a user can call any web page through it and the filter would make adjustments on the final page presentation. On this initial state, I was using frames and the onLoad event for the main frame (presenting the web page to be filtered). Every time the event is triggered, it's because a new web page is presented on the main frame so I call this filter function to make the adjustments. The main problem is that, first, the page is loaded and only then I can make the adjustments. This is not good considering user interaction issues, so I was trying to use AJAX. I wondered to use the onUnload event to know where the user is navigating to and call it through AJAX, using XMLHttpRequest to get the page, format it, and only then presenting it as the final state of art. Anyway, I was told that "probably" there isn't a way to know, at the onUnload event, where the user is navigating to.
Do you guys have a better idea to solve this? Any suggestion is valuable. Thanks for your attention!
|

05-22-06, 07:12 AM
|
|
Community VIP
|
|
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
onUnload is triggered before the page switch happens. If you have a script running, the switch won't happen until that script is done executing.
A timeout onUnload won't help either since the garbage collection would clear that from memory when switching to a new page.
I'd suggest you call the page using xmlHttpRequest and on the onLoad even for the xmlHttpObject, you parse the code before writing it to the main frame's body.
Note that JavaScript has no ability to change things on documents form outside your domain, due to security issues, when running in a browser. If you want to process external pages, it must happen on the server to be secure.
|

05-22-06, 08:46 AM
|
|
Newbie Coder
|
|
Join Date: May 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok TwoD! Thanks again for your answer!
Did you see my problem now? Your suggestion (to use XMLHttpObject and parse the code before writing to the frame) is exactly what I was considering to do, but my problem is to know what page will be called. The user may click an anchor or write an url at the address bar and I need to know what is this next url. I didn't design the current page being displayed by the filter, so it's complicated to parse all the code and re-address the href's to a certain javascript function that could give me the next url at the unload event because some pages call other functions to decide whether to go. See?
I would really appreciate if you or anyone here could suggest me anything to solve my problem with this client side filter.
Thanks and best wishes!
|

05-22-06, 09:58 AM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
EDIT: Nvm, I didn't read your last post. This won't do what you wanted.
You could try this.
This will redirect all links on your page that go to external sites to a PHP page that will log the url in an txt file and redirect to the site the visitor actually wanted to see.
external.php
I think this is what you wanted more or less?
Last edited by nico_swd; 05-22-06 at 10:27 AM.
|

05-22-06, 12:14 PM
|
|
Community VIP
|
|
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If the user types something in the addressbar, no script can detect that. But if a link is followed, you can intercept the redirect and do it your way by parsing all the links onload, like in the code posted. A script has on way of knowing where the browser will be sent to, so a site can't block you from going to some other site.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|