Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing Javascript code "on the spot" in Chrome?

I have a page in chrome which contains many textboxes and I wish to feed values automatically to them. I already have the list of name-value pairs, so if I could simple execute a series of Javascript commands on the form "document.getElementsByName(NAME)[0].value = VALUE;" I'll be done (I hope...)

So the question is - can I run a JS code "on the spot", or do I have to use a content script somehow?

like image 625
Gadi A Avatar asked Apr 09 '11 08:04

Gadi A


People also ask

How do I run JavaScript locally?

If you save your JavaScript in it's own file, you can run the entire file at once with nodejs by typing node <filename> where filename is the file you want to run. If you have node installed and you are using a text editor to write JavaScript in separate files you can use your editor to run your code.

How is JavaScript executed in browser?

The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute. In contrast, JavaScript has no compilation step. Instead, an interpreter in the browser reads over the JavaScript code, interprets each line, and runs it.

How do I see JavaScript code in browser?

For most browsers, to view inline JavaScript in the HTML source code, do one of the following. Press the Ctrl + U keyboard shortcut. Right-click an empty area on the web page and select the View page source or similar option in the pop-up menu.


2 Answers

I'm not sure how far it will get you, but you can execute JavaScript one line at a time from the Developer Tool Console.

like image 30
JustinStolle Avatar answered Sep 30 '22 15:09

JustinStolle


Right click on the page and choose 'inspect element'. In the screen that opens now (the developer tools), clicking the second icon from the left @ the bottom of it opens a console, where you can type javascript. The console is linked to the current page.

like image 99
KooiInc Avatar answered Sep 30 '22 16:09

KooiInc