rgarimella
asked on
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/in dex01.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">A uthorities </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.ht m 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.h tm" and I click on Authorities, the path resolves to
au/au/overview/overview/pa ge5.htm
Any help is greatly appreciated.
Thanks
RG
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/in
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">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.ht
How can this be changed within the existing code.
If I store the full path in the cookie like "overview/overview/page5.h
au/au/overview/overview/pa
Any help is greatly appreciated.
Thanks
RG
bookmark.js
function bookmarkit(){
//alert("bookmarkit called");
//tmout = setTimeout("gotoBkm()", 1000);
if (Content.lastPage){
set_cookie ( "bookmarkcd", "false", -1, -1, -1 );
}else{
setBookmark(Content.window.location);
}
}
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 );
return;
}
// 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;
}else{
Content.location.href = new_pathname;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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>
</frameset>
Also all this is going on a CD Rom instead of a webserver
<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>
</frameset>
Also all this is going on a CD Rom instead of a webserver
So what is your full URL path in the browser for your CD?
And what is the content of your WM_readCookie() function?
And what is the content of your WM_readCookie() function?
Also show WM_readCookie() function.