Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Lolu chungechunge lwabekwa kunqolobane. Uyacelwa ubuze umbuzo omusha uma udinga usizo.

How to set a bookmark from javascript?

  • 15 uphendule
  • 15 zinale nkinga
  • 121 views
  • Igcine ukuphendulwa ngu AlexSerov

more options

A web site is working using POST (not GET), so all the pages have same URL. With previous versions window.sidebar.addPanel(page_title, url,); worked, no it does not. Any way to achieve the same in current FireFox version?

A web site is working using POST (not GET), so all the pages have same URL. With previous versions window.sidebar.addPanel(page_title, url,''); worked, no it does not. Any way to achieve the same in current FireFox version?

Isisombululo esikhethiwe

Not that I know of without programming this in a extension as this would require chrome privileges to run such code.

Funda le mpendulo ngokuhambisana nalesi sihloko 👍 0

All Replies (15)

more options

Can you post the web page(s) so we can look at them? A standard is to make a bookmark, or click and hold the icon on the address bar and move it to the desktop.

more options

Here is the website application I am running: hybridjava.com. There are several pages, all accessed with POST. Regular way to set bookmark on the other pages than the first one does not work - it remembers only http://www.hybridjava.com URL which is the first page only. The traditionally recommended way to set bookmarks for other pages is to generate a page that contains a different (GET) URL that the server interprets by showing one of the secondary pages. For Firefox the javascript that worked was:

 if(window.sidebar){ // Firefox / Mozilla 
   window.sidebar.addPanel(page_title, url,); 

NOW IT DOES NOT WORK

Okulungisiwe ngu AlexSerov

more options

The window.sidebar code is marked as obsolete, so it is possible that it is no longer supported.

more options

I know that it is obsolete. But what to do now to bookmark pages reached via POSTs? That breaks functionality of sites, far not only of my site.

Similar functionality in IE is achieved by the following javascript code: if(window.external){ // Internet Exploiter

   window.external.AddFavorite(url, page_title);

Okulungisiwe ngu AlexSerov

more options

The Web Console (Firefox/Tools > Web Developer;Ctrl+Shift+K) shows this error:

TypeError: window.sidebar.addPanel is not a function

You can use this bookmarklet to change the URL in the location bar and use the star on the location bar to bookmark a specific page.

javascript:function add_bookmark(url,page_title){location.href=url}CreateBookmarkLink();void(0);
more options

CreateBookmarkLink() that I was able to google up is itself implemented using window.sidebar.addPanel (which is obsolete). May you please give a more clear view of what you suggest?

more options

The above posted bookmarklet redefines the add_bookmark() function that is called by the CreateBookmarkLink() function.
So what happens when you run this bookmarklet code is that the page reloads with the URL (location.href=url) that is specified in the CreateBookmarkLink() function.

That way you can click the star to bookmark the current page with the correct URL.

more options

Looks like you have already tested it 8-), thank you. To make it perfect - is there a way to "click" the star programatically (from javascript)? [so that it provides functionality not less than that provided by IE]

more options

Isisombululo Esikhethiwe

Not that I know of without programming this in a extension as this would require chrome privileges to run such code.

more options

The solution is still too far from good - without if(window.sidebar) I am not even able to guess that it happens under Firefox.

more options

You can see that the URL in the location bar changes after you have run this JavaScript bookmarklet code.
Once you have clicked that star or use Bookmarks > Bookmark this page then you should get a highlighted star on the location bar once you would run the bookmarklet code another time on a next visit.

You could create an extension to emulate and inject the window.sidebar.addPanel() function in a web page.

more options

I am faaar from being javascript guru. Sorry about that and my thanks. I have added the following function:

function add_bookmrk(url,page_title) { 
    alert(' !!! ');
	javascript:function add_bookmark(url,page_title){location.href=url}CreateBookmarkLink();void(0);
    alert(' ??? '); 
}

The first alert shows up, but then it continues showing the first alert endlessly and never show the second.

Okulungisiwe ngu cor-el

more options

That would be something like this to get an alert:

javascript:function add_bookmark(url,page_title){location.href=url;alert(' ??? ')}CreateBookmarkLink();void(0);

You can also use alert('<'+url+'>'); to see the URL that is used

more options

Progress with the following code: (thank you!) <script language="JavaScript1.2" type="text/javascript"> javascript:function add_bookmark(url,page_title){ location.href=url;alert(' ??? ');alert('<'+url+'>'); } function CreateBookmarkLink() {

title = "$page"; 
url   = "$url";
add_bookmark(url,title);

} </script> <INPUT TYPE="BUTTON" VALUE="Bookmark this page" OnClick="CreateBookmarkLink()"> ////////// issues (small): - the first alert pops up for a second then goes away itself - the second alert does not show up at all - the URL changes in the command line, but the star does not shine.

more options

So I end up with

<script language="JavaScript1.2" type="text/javascript">
javascript:function add_bookmark(url,page_title){
	location.href=url;
}
function CreateBookmarkLink() {
	title = "$page"; 
	url   = "$url";
	add_bookmark(url,title);
} 
</script>

It works same way both in Firefox, IE and Chrome. Though it does not ACTUALLY set the bookmark it looks the best solution overall.

Okulungisiwe ngu cor-el