Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run my own javascript on a (loaded) page?

Can I run my own javascript code in a browser when viewing a page?

For example I have page index.html. In that I want to run this javascript function

function myFunction()
{

 alert("Say Hi");

}

I want to call this function through some browser interface because I don't have access to the source code of the web.

like image 778
Radek Avatar asked Jul 13 '12 04:07

Radek


People also ask

How do I run JavaScript on another website?

In the shortcut editor, tap at the top of the action list, begin typing “Run JavaScript…” in the search field, then tap the Run JavaScript on Web Page action to add it to the shortcut editor. Write your script in the text field in the Run JavaScript on Web Page action.

Can you run a JavaScript file independently?

The answer is – Yes. One way to run Javascript without a browser is to: Install an independent Javascript runtime such as NodeJS. Then run the Javascript in the command line – node SCRIPT.

How do I run JavaScript on its own?

To execute JavaScript in a browser you have two options — either put it inside a script element anywhere inside an HTML document, or put it inside an external JavaScript file (with a . js extension) and then reference that file inside the HTML document using an empty script element with a src attribute.

Can you run JavaScript as standalone application without the browser?

You can run JavaScript console in terminal or any command-line interface using Node. js, an open-source, platform-agnostic runtime that executes JavaScript outside a web browser.


2 Answers

Yes. Just how depends on which browser you're using:

  • For Chrome and Safari you'll use the built-in Web Inspector—see the instructions on this page.

  • Firefox has the built-in Web Console, but the more advanced add-on Firebug is very popular.

  • The Internet Explorer equivalent is Developer Tools, which you can launch with F12.

like image 54
Jordan Running Avatar answered Sep 30 '22 05:09

Jordan Running


You can use a bookmarklet, the javascript console or a browser plugin to run your own code in an already loaded page.

Greasemonkey is a browser plugin for Firefox that provides a framework for running your own javascript code in other web pages that are already loaded.

like image 36
jfriend00 Avatar answered Sep 30 '22 07:09

jfriend00