Development :
K-Meleon Web Browser Forum
K-Meleon development related discussions.
Javascript
Posted by:
paul
Date: January 29, 2005 06:32PM
How do you implement javascript code in macros?
Re: Javascript
Posted by:
rmn
Date: January 29, 2005 07:12PM
The only way is by open()ing a "javascript:" code.
open("javascript: INSERT JS CODE HERE");
Re: Javascript
Posted by:
paul
Date: January 29, 2005 07:57PM
ok, but how do i format the JS
if i just arbitrarily paste block of code where you said to and start k-meleon, it gives some errors and then when i hit the toolbar button to execute the macro it spews more errors
Re: Javascript
Posted by:
jsnj
Date: January 29, 2005 08:07PM
Gotta give it a macro name. Then you have to reference the macro name in menus.cfg or accel.cfg
In macros:
MacroName{
open("javascript: INSERT JS CODE HERE");
}
In menus: Find the menu you want to put it in
macros(MacroName, Menu Name)
Re: Javascript
Posted by:
paul
Date: January 29, 2005 08:17PM
I understand all of that.
I am talking about the formatting
It looks like the javascript on macros needs to be written without any line breaks at all
I want to know how it has to be formatted to be correctly read by k-meleon in more of a text processing sense
Re: Javascript
Posted by:
jsnj
Date: January 29, 2005 08:37PM
It looks like the javascript on macros needs to be written without any line breaks at all
Correct. But there's no other "special formating" AFAIK. Just follow the example above. There are some conflicts that arise from certain JS code when read in macros that need adjustment. RMN will have to fill you in on that if he can. But most bookmarklets work without a problem.
Re: Javascript
Posted by:
caraz
Date: January 29, 2005 10:13PM
Basically, I want to create a macro that switches the integer/string value of some k-meleon user prefs ever 15s or so using javascripts setinterval() timer
can anybody give me some code and let me fill in the blanks?
Re: Javascript
Posted by:
jsnj
Date: January 29, 2005 11:52PM
I'm not sure if there are enough users floating around the forum who are fluent enough in JS code to write out the generic formula. RMN may or may not be able to. I definitely can't : - | All the JS code in the default macros file is based on bookmarklets found on the web. Some were slightly altered, but none were written from scratch. The only macro commands even vaguely similar to time intervals are event macros:
OnLoad
OnStartup
OnQuit
OnCloseWindow
OnCloseGroup
OnWMAppExit
Re: Javascript
Posted by:
jsnj
Date: January 29, 2005 11:53PM
I forgot OnOpenWindow
Re: Javascript
Posted by:
caraz
Date: January 30, 2005 12:01AM
How about breaking down the code for the Reload Macro.
It seems to be the most complicated but it does use some time interval code.
Re: Javascript
Posted by:
caraz
Date: January 30, 2005 12:41AM
Is there a way to run certain code (just plain macro, not javascript) every time a page is loaded if a certain condition is met? If so, how? (an example is worth a thousand words)
Re: Javascript
Posted by:
jsnj
Date: January 30, 2005 03:34AM
Yes, the last session macro does that with the Onload macro. So you can take a look at the Onload macro and the macros it references. What do you want to do specifically? Is it confidential? It's hard to give a generic example because certain prefs can be changed. Others can't. And certain things require different methods. It all depends. So what exactly do you want to happen at certain intervals?
Re: Javascript
Posted by:
rmn
Date: January 30, 2005 11:22AM
@paul:
> It looks like the javascript on macros needs to be written without any line breaks at all
Yes, and of course you'll also need to escape the quotation marks, e.g.
open("javascript:alert(\"something\")")
@caraz:
> Basically, I want to create a macro that switches the integer/string value of some k-meleon user prefs ever 15s or so using javascripts setinterval() timer
Unfortunately, you can't. The macro language is separate from js codes (you cannot run macros from js), and there is currently no macro to do timed looping.
Re: Javascript
Posted by:
caraz
Date: January 30, 2005 03:34PM
Thanks for all the help. I was able to use the OnLoad event in place of a timed interval.