I would like to know is it possible to save some, for example,simplemath.js file with
function ADD(a, b)
{
return a + b;
}
simple function, run opera’s or some other browser’s javascript console, include somehow this (simplemath.js) file, call ADD(2, 5), and get a result in console or execute javascript code on current web page and manipulate with it’s content. How can I do that? How can I use javascript functions from external files in web-browser’s javascript console?
// EDITS
simplemath.js is just local file, somewhere on hard drive (c:\temp\simplemath.js), no localhost web servers running. I want to run scripts from it on any web page and get result similar to typing javascript: function ADD(a, b){return a+b;} alert(ADD(1, 41);) in browsers address bar, but via console, and load ADD function from external file.
You can include your
simplemath.jsfile as a userscript into Opera:You can enable it globally or on specific pages only. Opera does also support greasemonkey scripts, a Firefox addon. Yet (at least in FF) they usually run in a sandbox, so they will not leak global variables into the webpage where it would be accessible from the console (unless you explicitly state so).