|
-
July 26th, 2002, 10:09 AM
#1
Bookmarking, by Javascript
Hi,
I am fairly new to Javascript. I am sure for the scripting gurus here this is a fairly simple task.
I want to have a URL (or button) when clicked should add the current page to 'Favourites'. I did some searching around and found i can use 'window.external.AddFavorite' function to do that in IE alone (and i am fine withit).
But my website is based on frames and my top frame is static and bottom frame keeps changing. i.e. I have Index.html (which has a frameset with two frames, top and main. The top remains static and frame 'main' has different webpages. So this 'Bookmark' url in top frame when clicked should store the current position which is index.html with whatever current page in 'main'. When manually done in browser (by clicking add to favourites) this is what happens.
All your help is greatly appreciated.
Thank you.
-
July 26th, 2002, 10:45 AM
#2
Try this...
You can supply the url which you wish to add to favourites to the method like so:
window.external.AddFavourite('http:\\www.hello.com\thissite\thispage.html');
So in your case code
window.external.AddFavourite(window.parent.frames('main').location);
If you wish to load the page within the frameset, you might have to be a little more subtle.
You could code supply the desired src of the main frame as an asp argument and insert it using asp, or append it as a # value and use something like this in index.html
<body onload="javascript oFunction();">
<script>
function doFunction(){
window.frames('main).src = window.location.hash;
}
cheers
Last edited by Surrendermonkey; July 26th, 2002 at 10:50 AM.
-
July 26th, 2002, 11:11 AM
#3
Thanx for the reply.
But the code gives a error. Are you suggesting i have to pass a parameter like
'parent.main.document.location'. If yes, this causes the page in the frame 'main' to be bookmarked and when recalled would bring that page alone (without the outer index.html).
Let me explain a little in detail. Index.html is a frameset with two frames 'top' and 'main'. 'Top' has top.html which contains all the links. 'Main' frame has different pages which can be obtained by clicking links in top.html. Suppose at a particular point (cause of users actions) 'main' has XYZ.html, and the user decides to bookmark (the link to bookmark is in top.html). The user should be able to recall index.html with top.html in 'top' and XYZ.html in 'main'.
The browser (when clicked 'Favourites -> Add to Favourites' menu ) does this. So i wanted something simillar using javascript.
Thanx again for your time.
-
July 29th, 2002, 11:20 AM
#4
Try this
I was using window.location when document.location might have been better...
For your add-to-favourites link in top.htm, use this:
<script>
function addToFavourites(){
window.external.AddFavorite('http://www.yourserver.com/yoursite/index.html#' + window.parent.frames['main'].location, 'default title');
}
</script> along with something like:
<a href="javascript:addToFavourites();">Add</a>
In your index.html framespage, call a function from the frameset onload event, like this
<frameset onload="javascript:SetSrcFromHash();" src="defaultsourcepage.htm"> and script this function like this:
<script language="javascript">
function SetSrcFromHash(){
var mainSrc = new String(document.location.hash);
if (mainSrc != ''){
mainSrc = mainSrc.substr(1);
document.all.mainFrame.src = mainSrc;
}
}
</script>
See how you go.
Last edited by Surrendermonkey; July 30th, 2002 at 03:38 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|