PDA

View Full Version : How to bookmark current page, not just your domain?



bobbby
01-14-2006, 02:01 AM
Im using the bookmark script:

http://www.dynamicdrive.com/dynamicindex9/addbook.htm

I got it working, but you have to specify the page in advance, so I chose www.dynamicdrive.com. But I want people to be able to bookmark the current page: e.g. http://www.dynamicdrive.com/forums/newthread.php.

Is there a way to let the script read the url you're at?

My link code:

<a href="javascript:bookmarksite('dynamic drive', 'http://www.dynamicdrive.com')">bookmark</a>

Thanks for reading this :)

jscheuer1
01-14-2006, 07:54 AM
<a href="javascript:bookmarksite('dynamic drive', 'http://www.dynamicdrive.com/forums/newthread.php')">bookmark</a>

Or, to bookmark the actual page you are on:


<a href="javascript:bookmarksite(document.title, window.location.href)">bookmark this page</a>

bobbby
01-14-2006, 09:30 AM
Thanks for answering everybody's questions John.

I think you got the right idea with your your 2nd snippet of code, but for some reason I cant get it to work...:(

I'll just post my html file:


<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Untitled Page</title>
<script type="text/javascript">
/***********************************************
* Bookmark site script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}
</script>
</head>
<body bgcolor="#ffffff">
<p><a href="javascript: bookmarksite(document.title, window.location.href)">bookmark this page</a></p>
</body>
</html>


Here's the error Opera gives (doesnt work in IE either):


Untitled Page
http://www..../untitled.html
Javascript URL thread: "javascript: bookmarksite(document.title, window.location.href)"
Error:
name: TypeError
message: Statement on line 9: Could not convert undefined or null to object
Backtrace:
Line 9 of inline#1 script in http://www...../untitled.html
window.external.AddFavorite(url, title);
Line 1 of unknown script
bookmarksite(document.title, window.location.href);

Any clue what the problem is?

jscheuer1
01-14-2006, 10:00 AM
Well, this script (at least with my modifications) won't work locally, the page needs to be live. Also, the script is not rated for Opera to begin with so, forget about that browser when testing. I copied your code, published the page (http://home.comcast.net/~jscheuer1/side/smart_phone_h.htm), clicked on the link, and got a nice bookmark for my trouble.

bobbby
01-14-2006, 11:25 PM
Not surprisingly, you were right!

While making the test page I tested it locally in IE and it didnt work. Then I got the smart idea to test it online but I forgot the script didnt work in Opera! :D

Your alteration really improves that script. Cant DD post your code as well?
Downside is that your signature wouldnt be true anymore :)

Thanks again.