PDF download Download Article PDF download Download Article

JavaScript injection is a process by which we can insert and use our own JavaScript code in a page, either by entering the code into the address bar, or by finding an XSS vulnerability in a website. Note that the changes can only be seen by you and are not permanent. This is because JavaScript is a "client-side" language.

Method 1
Method 1 of 1:

Using JavaScript Injections

PDF download Download Article
  1. Try these injections:
    • Note - If you use Firefox, you will have to use another way, like cmd-shift-k on a Mac
    • javascript:alert("Hello!");
    • To bring up an alert box saying "Hello!":
    • To bring up 2 alert boxes, the one in the front will say "Hello" and once you click OK, the one saying "World" will appear:
    Advertisement
    • To change the value of form [0] to something:
    • To change the background color to blue. You can put any other color in the place of blue to change it to a different color:
  2. \t\t" + location.protocol + "//" + location.hostname + "/" + "\nThe address URL is:\t\t" + location.href + "\n" + "\nIf the server names do not match, this may be a spoof.");
    • To see the real server name of the site you are looking at. You should use it if you think that you are viewing a spoofed website, or anytime just to make sure:
  3. javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval('A()',5); void(0);
    • To make pictures fly around. Make sure to find a site like Google Images so there are more pictures!(If you press the refresh button, it goes really fast, but might only work with macOS):
  4. javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=Math.cos(R*x1+i*x1+x2)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval('A()',5); void(0);
    • To spin circle of pictures. It funnels the pictures in a snake-like motion:
    • To move things around on the webpage:
  5. Advertisement

Community Q&A

Search
Add New Question
  • Question
    Is this the equivalent of the JavaScript console?
    Community Answer
    Community Answer
    Yes; this is much less limited, though. The JavaScript console in the dev tools has features such as auto-completion and can show your history of executed commands. Additionally, you can check things such as break points for analyzing and debugging your code.
  • Question
    In Step 3, how do I select a form? The example specifies forms[0], but how do I actually specify a certain form if the code has several forms within it?
    Community Answer
    Community Answer
    You can select forms from the website using document.forms. The forms[0] indicates that it is the 1st form on the page, because the collection starts at 0. You can make a form with the HTML form tag, and you can learn more at sites like w3schools.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Video

Tips

  • Only you can see the changes.
  • The changes are not permanent. It's a static change that won't affect any server information.
  • If you're using a browser with an address bar that doubles as a search bar (e.g., Google Chrome), make sure that after you type in the JavaScript code, you select your address bar for processing the code, not the search function.

Show More Tips
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement

You Might Also Like

Appear to Edit Text on Any Website4 Easy Ways to Edit Text on Any Website Using HTML
Change Button Color in JavascriptChange Button Color in Javascript
Make a JavaScript Image RolloverMake a JavaScript Image Rollover
Print in Javascript4 Ways to Print in JavaScript: Console, Window Alert, & More
Set Background Color in HTML3 Methods to Set a Background Color with HTML & CSS
Make Text Blink in HTML Make Text Blink in HTML: Easy Tutorial
Create a Calculator Using HTMLCreate a Calculator Using HTML
Program with VBScriptProgram with VBScript
Fake Discord Messages Using Inspect Element Make Fake Discord Messages With Inspect Element
Enable JavaScript Turn On JavaScript: Easy Steps for Chrome, Safari, Edge, More
Make a Game with Notepad3 Cool Ways to Make Your Own Game with Notepad
Disable JavaScript Turn Off JavaScript on Chrome, Safari, Edge, and More
Make It Look Like You Are Hacking Make It Look Like You are Hacking
Change Text Color in HTML Change Text Color in HTML and CSS
Advertisement

Expert Interview

Thanks for reading our article! If you'd like to learn more about dealing with HTML, check out our in-depth interview with Jessica Andzouana.

About This Article

Jessica Andzouana
Co-authored by:
Software Engineer
This article was co-authored by Jessica Andzouana. Jessica Andzouana is a Software Engineer based in the San Francisco Bay Area. With over five years of professional experience in front-end development, digital art, and design, she is passionate about emerging technologies such as blockchain and AI. Her background as both a programmer and artist, paired with a highly design-conscious mindset, provides her a fresh perspective and unique skill set to produce creative solutions in her field. She works at Alcacruz as a Software Engineer, and received a dual BS/BA degree from Santa Clara in Computer Science and Studio Art. This article has been viewed 524,510 times.
How helpful is this?
Co-authors: 46
Updated: August 28, 2025
Views: 524,510
Categories: JavaScript
Thanks to all authors for creating a page that has been read 524,510 times.

Is this article up to date?

Advertisement