•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,745 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,499 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1189 | Replies: 5
![]() |
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
I have a problem as following...
# I have stored some value in session to reach a Page "A"
# I have other pages "B", "C", "D".
# If I am moving from Page "A" to "B", I should not clear my session value but If I am moving from "A" to "C" or "A" to "D", then I have clear some values in session.
# I have clear it on body unload of "A" on condition. Is there any way to find the URL which I am landing via javascript? Is there any other way or work around to solve this problem.
Note: I have menu in my left frame and content in right frame. All my links to move from "A" to "B", "C" and "D" are in menu.
# I have stored some value in session to reach a Page "A"
# I have other pages "B", "C", "D".
# If I am moving from Page "A" to "B", I should not clear my session value but If I am moving from "A" to "C" or "A" to "D", then I have clear some values in session.
# I have clear it on body unload of "A" on condition. Is there any way to find the URL which I am landing via javascript? Is there any other way or work around to solve this problem.
Note: I have menu in my left frame and content in right frame. All my links to move from "A" to "B", "C" and "D" are in menu.
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation:
Rep Power: 5
Solved Threads: 47
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation:
Rep Power: 5
Solved Threads: 47
In Javascript, you cannot find where the user is going to go next, unless you strictly control the user's movement; something that you can only do within the realms of them navigating using your own controls.
i.e. it's not possible, unless it would suffice to only be notified of such an event if the user goes somewhere using a link directly on your page, in which case, it's easy; just add an onclick handler to all of the links to those other pages. You know where the link is going, because you wrote the link address. If you don't hardcode the link addresses for whatever reason, the link element's
You cannot, ever, find out if a user is typing in a new URL and is about to hit enter, and browser forwards/backwards actions can't be reliably monitored, nor averted.
At the server, you can find out where the user has been going ( within your site ) by looking at where the user has come from ( REQUEST_URI in the HTTP header ). I don't believe that this is possible in Javascript.
i.e. it's not possible, unless it would suffice to only be notified of such an event if the user goes somewhere using a link directly on your page, in which case, it's easy; just add an onclick handler to all of the links to those other pages. You know where the link is going, because you wrote the link address. If you don't hardcode the link addresses for whatever reason, the link element's
href property can be read, and obviously, you could do something more useful than this example with the address: ( i.e. check to see if it is an address for which your session needs to be cleared ) HTML Syntax (Toggle Plain Text)
<a href="http://somewhere.com" onclick="alert('Going to: ' + this.href);return true;">Going where?</a>
At the server, you can find out where the user has been going ( within your site ) by looking at where the user has come from ( REQUEST_URI in the HTTP header ). I don't believe that this is possible in Javascript.
If it only works in Internet Explorer; it doesn't work.
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 943
Reputation:
Rep Power: 5
Solved Threads: 47
When the link has been clicked, put its' id ( or better, the object itself, or its href, or whatever ) in a global variable.
You might be better off using a javascript-controlled cookie all throughout the site; ie. on every page onload event, read the last URL from the cookie, do whatever you'd intend do when the previously loaded page was unloaded, then write the current URL to the cookie. That way, whenever the user moves between pages, you can find out where they came from. That's gotta be more useful, and flexible, and I can't think of any situation where that would be less suitable than trying to find out where the user is going.
...
<script type="text/javascript">
var last_link = 0;
function unloading()
{
if( last_link != 0 ){ ... }
}
function set_last_link( obj )
{
last_link = obj;
}
</script>
</head>
<body onunload="unloading( );">
....
<a onclick="set_last_link( this ); return true;"/>
...You might be better off using a javascript-controlled cookie all throughout the site; ie. on every page onload event, read the last URL from the cookie, do whatever you'd intend do when the previously loaded page was unloaded, then write the current URL to the cookie. That way, whenever the user moves between pages, you can find out where they came from. That's gotta be more useful, and flexible, and I can't think of any situation where that would be less suitable than trying to find out where the user is going.
If it only works in Internet Explorer; it doesn't work.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- how can i pass a value from java script to JSP scriplet (JSP)
- Email validation using java script (JavaScript / DHTML / AJAX)
- Java Script new line (JavaScript / DHTML / AJAX)
- Java script - wordwrap ? (HTML and CSS)
- FireFox config setting through Java Script (Community Introductions)
- How to Embed CheckList Box on HTML Page using Java Script (HTML and CSS)
- A question on java script?(Please answer ASAP) (Java)
- java script for main menu (ASP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Http request error when using AJAX.
- Next Thread: Slideshow for the images


Linear Mode