Improvement requests :  K-Meleon Web Browser Forum
Use this forum to talk about a feature you're missing. 
Javascript
Posted by: paul
Date: January 29, 2005 06:33PM

How do you implement javascript code in macros?
How do you format the code so k-meleon will accept it?

Options: ReplyQuote
Re: Javascript
Posted by: atordo
Date: January 29, 2005 07:40PM

I'd like to see javascript implemented on bookmarks. I use Bookmark4U, which stores bookmarks on a mysql database on a remote server. To bookmark a page it uses the following code on a bookmark in the browser:

javascript:void(open('http://site.address/path/bookmark.php?userid=&url='+escape(document.location)+'&pagetitle='+escape(document.title)+'&dummy='+Math.random(),'bookmark4u','width=600,height=400,scrollbars=1,resizable=1'));

This worked ok in Firefox, thus passing the URL and the title to the php script. But K-Meleon does nothing, so I have to cut&paste. This is not very terrible, but far from comfortable. If somebody knows some trick to make this work in K-Meleon please post.

Options: ReplyQuote
Re: Javascript
Posted by: jsnj
Date: January 29, 2005 08:13PM

If the JS code doesn't work when called from one of your KM bookmarks then it won't work in macros. Have you bookmarked the JS code using KM's bookmark plugin?

Options: ReplyQuote
Re: Javascript
Posted by: atordo
Date: January 29, 2005 10:26PM

I've not seen any KM's bookmark plugin. I use the Netscape one, because if all of them are disabled (Netscape, IE and Opera), the bookmarks option just disappears from menu.

I don't need to import bookmarks from other browsers, so if you tell me how to enable KM bookmark plugin (it's not listed under Preferences/Plugins), I'll thank you.

Options: ReplyQuote
Re: Javascript
Posted by: jsnj
Date: January 29, 2005 11:59PM

KM's bookmark plugin is called Netscape Bookmark plugin. Go to its 'Edit' window and create a new bookmark. Copy the JS code into the URL field, save it and then see if it works.

Options: ReplyQuote
Re: Javascript
Posted by: atordo
Date: January 30, 2005 05:04PM

Well, that's what I was trying from the beginning and it just did nothing. But playing with the options I've discovered that if the "Block popup windows" is disabled (under Preferences/Privacy), the code works as expected. It must be that "open" that gets intercepted.

I'd rather copy&paste than suffer popups, but may be this code should be allowed to work even if the block option is selected, because going to the menu and selecting a bookmark is definitely an user action, not an unsolicited one.

Options: ReplyQuote
Re: Javascript
Posted by: rmn
Date: January 30, 2005 06:27PM

To get around the popup blocking, you can try using K-Meleon's opennew() macro function instead of javascript's open().

opennew("javascript:location.href='http://site.address/path/bookmark.php?userid=&url='+escape(document.location)+'&pagetitle='+escape(document.title)+'&dummy='+Math.random(),'bookmark4u','width=600,height=400,scrollbars=1,resizable=1'");

Of course, that needs to go to macros.cfg.

Options: ReplyQuote
Re: Javascript
Posted by: atordo
Date: January 31, 2005 12:56AM

Thanks for the tip rmn, you are the man! smiling smiley

With opennew it tries to bookmark about:blank (it seems that document.location and document.title correspond to the new page being opened), but open works just fine.

Note that the same results (opening Bookmark4U in the same layer) can be accomplished avoiding the "open" in a bookmark: javascript:location.href='http://site.address... But now that the macro is written, I'll get rid of the bookmarks plugin.

Options: ReplyQuote
Re: Javascript
Posted by: rmn
Date: January 31, 2005 10:28AM

> With opennew it tries to bookmark about:blank (it seems that document.location and document.title correspond to the new page being opened), but open works just fine.

Ah, yes, should've realized that.. This one should be correct:

opennew("javascript:location.href='http://site.address/path/bookmark.php?userid=&url='+escape('".$URL."')+'&pagetitle='+escape('".$TITLE."')+'&dummy='+Math.random(),'bookmark4u','width=600,height=400,scrollbars=1,resizable=1'");

Options: ReplyQuote
Re: Javascript
Posted by: atordo
Date: January 31, 2005 08:55PM

Bingo! That one works perfectly. Thanks again.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.