Problem with location.href

Hi Folks,

I am writing a cookie based bookmarking feature, so that users can return back from where they have left.

Here is my folder structure

index.htm // open the page to launch menu.htm in the window and then close
menu.htm // menu for all the lessons

Menu is a simple a href

<a href="overview/overview/index01.htm">overview</a>

This is the first line of code for index01.htm
<frameset rows="100%,*" frameborder="no" border="0" framespacing="no" onLoad="getBookmarkCD();" onbeforeunload="bookmarkit();">

<a href="au/au/index01.htm">Authorities</a>

so on, when the page closes I write the page number in a cookie. This works fine.

My problem is if the bookmark info is for the Overview lesson and the user clicks on the Authorities lesson, my path is not able to go to the overview lesson.

The cookie is looking for filename page5.htm in the overview folder. So when the user clicks on the Authorities folder it is still looking for page5.htm which is not in the Authorities folder but it is in the overview folder.

How do i resolve my path because with the code below my path is resolving to
au/au/page5.htm instead of

overview/overview/page5.htm when the overview link is clicked, it works fine when authorities hyperlink is clicked in the menu. The folder path only resolves to the hyperlink clicked.

How can this be changed within the existing code.

If I store the full path in the cookie like "overview/overview/page5.htm" and I click on Authorities, the path resolves to


Any help is greatly appreciated.



function bookmarkit(){
	//alert("bookmarkit called");
	//tmout = setTimeout("gotoBkm()", 1000);
	if (Content.lastPage){
		set_cookie ( "bookmarkcd", "false", -1, -1, -1 );
function getBookmarkCD() {
		//var lastpage = WM_readCookie("bookmarkcd");
		var lastpage = WM_readCookie("bookmarkcd");
		//alert("lastpage > " + lastpage);
		// make sure we have a last page to return to.
		if ( lastpage == 'false' ) {
			//setBookmark( window.location );
		// we have a bookmarked location
		if (lastpage){
			if ( confirmBookmark( lastpage ) ) {
				returnToBookmark( lastpage );
			} else {
				//setBookmark( window.location );
// confirm that you want to return to the last bookmarked page
function confirmBookmark( title ) {
        result = confirm('Do you wish to return to your last location (' + title + ')?');
        if ( result ) {
                return true;
        } else {
                return false;
function getFilename ( this_location ) {
	// get path part of URL
	var this_pathname = this_location.pathname;
	// split on /
	var dirs = this_pathname.split('/');
	// filename is last element
	return dirs[dirs.length-1];	
function setBookmark( this_location ) {	
	var strNav = Navigation.count ;
	//alert("strNav > " + strNav);
	var filename = getFilename( this_location ); 
	//alert("filename > " + filename);
	//document.cookie = "bookmarkcd=" + filename; // Bookmark the filename into  a Cookie
	set_cookie ( "bookmarkcd", filename, 2020, 12, 15 );
	set_cookie ( "strNavCounter",  strNav, 2020, 12, 15 );
	//document.cookie = "strNavCounter=" + strNav; // Put the Navigation Counter Value into a Cookie
function returnToBookmark( lastpage ) {
	var counter =  WM_readCookie("strNavCounter");
	Navigation.count = counter ; 
	var this_location = window.location;
	var this_pathname = this_location.pathname;
	var new_pathname  = "";
	// split on /
	var dirs = this_pathname.split('/');
	// set filename (last value) to the lastpage we got
	dirs[dirs.length-1] = lastpage;
	for ( var i=0; i < dirs.length; i++ ) {
		new_pathname = new_pathname  + "/" + dirs[i];
	// remove first character
	new_pathname = new_pathname.slice(1);
	// set the location parameter with the new pathname
	// and apparently jump to the page
	//this_location.pathname = new_pathname;
	var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
	if (ie7){
	    Content.location.href = lastpage;
	    Content.location.href = new_pathname;

Open in new window

Who is Participating?
ZvonkoConnect With a Mentor Systems architectCommented:
By the way, the answer to your question is simple: use path relative to web server root by prepending forward slash to the path: /
ZvonkoSystems architectCommented:
What is Content?
Also show WM_readCookie() function.
ZvonkoSystems architectCommented:
or in more detail:
1.) every href starting with http:// can select the server and is the absolute path.
2.) every href starting with / references the path from the current web server root path.
3.) anything else not starting with / or href: is relative to the curent web page folder path.
rgarimellaAuthor Commented:
Content is the name of the Frame

<frameset rows="100%,*" frameborder="no" border="0" framespacing="no" onLoad="getBookmarkCD();" onbeforeunload="bookmarkit();">

<frame src="ab_03_01_0010.htm" name="Content" title="Main Content" SCROLLING="no" MARGINWIDTH="0" MARGINHEIGHT="0" FRAMEBORDER="no" BORDER="0" noresize>

<frame src="bottomnav01.htm" name="Navigation" title="Navigation" SCROLLING="no" MARGINWIDTH="0" MARGINHEIGHT="0" FRAMEBORDER="no" BORDER="0" noresize>


Also all this is going on a CD Rom instead of a webserver
ZvonkoSystems architectCommented:
So what is your full URL path in the browser for your CD?
And what is the content of your WM_readCookie() function?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.