|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
adding a bookmark using JS
i have written the following code to generate a bookmark for the current page:
Code:
function errorMsg()
{
alert("Your browser does not support this feature");
}
function addBookmark()
{
var urlValue = "http://www.trackerurl.com?url="+escape(window.location);
var titleValue = window.name;
if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
window.sidebar.addPanel(titleValue, urlValue,"");
} else if ((typeof window.external == "object") && (typeof window.external.AddFavorite == "function")) {
window.external.AddFavorite(urlValue, titleValue);
} else {
errorMsg();
}
}
1. The "titleValue = window.name;" does not seem to work correctly (what is the code to get the title of the current page?) 2. "(typeof window.external == "object") && (typeof window.external.AddFavorite == "function")" does not seem to work in IE which is what it is aimed at...if i use "if (window.external) it works fine...why? 3. Are there any other main browsers that I am not targeting with this code, and what should I do to add them? thanks |
|
#2
|
||||
|
||||
|
1. document.title
2. & 3. http://labnol.blogspot.com/2006/01/a...k-firefox.html
__________________
At least 98% of internet users' DNA is identical to that of chimpanzees |
|
#3
|
|||
|
|||
|
1) document.title is probably what you want.
2) I've wondered that myself. 3) Yes. Check out The Ultimate Add Bookmark Script.
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around. Check out my blog. |
|
#4
|
|||
|
|||
|
@kravvitz
The Ultimate Add Bookmark script seems little complex to me, since I'm not used to javascript...I like coding I can understand so I can play around with it if need be.... but regarding the site "http://labnol.blogspot.com/2006/01/add-to-favorites-ie-bookmark-firefox.html" posted by Fang.... how does this code work in Opera: else if(window.opera && window.print) { // Opera Hotlist return true; } I mean, as far as I can see, it is just returning true, so its not really doing anything...I haven't tested it, but even if it worked, I'd like to know HOW... thnx |
|
#5
|
||||
|
||||
|
Works in IE, FF and Opera:
Code:
<a href="#" rel="sidebar" onclick="if(document.all && !window.opera){ window.external.AddFavorite(location.href, document.title);return false; }else{ this.title = document.title; }" title="bookmark this page">Bookmark This Page</a>
__________________
At least 98% of internet users' DNA is identical to that of chimpanzees |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|