How To Add A Script Code In My Html In Real Time On Browser Open It
Solution 1:
IF I understand your question correctly -- that is, if you want to inject code into an existing webpage where you don't have access to the source code -- then:
The simplest way to do this is with a browser extension called TamperMonkey - it allows you to inject javascript into any webpage, based on the URL.
TamperMonkey scripts are installed (or written) in each person's browser, individually, and they only effect the webpage on that one computer. So, if your friend also wants to see the same effect, he also needs to install the TamperMonkey extension and add your script - which is why there are now millions of TamperMonkey users around the world. Hugely amazing product - many thanks to Jan Biniok.
There are also tons of pre-existing Tampermonkey scripts at the GreasyFork script repository.
TamperMonkey comes out of a previous extension called GreaseMonkey, so anywhere you see variations of that name, it probably also relates to TamperMonkey. The documentation for TamperMonkey is here:
Solution 2:
Why don't you just add it inside the HTML directly?
However, you can insert any tag with content into your HTML via JavaScript like this:
var htmlToInsert = '<div class="inserted">I am added dynamically</div>';
var target = document.querySelector('#container');
target.innerHTML += htmlToInsert;
#container {
padding: 10px;
background: #000;
color: #fff;
}
.inserted {
margin: 20px 0;
width: 200px;
height: 200px;
background: #c00;
}
<div id="container">I've been here all the time</div>
Post a Comment for "How To Add A Script Code In My Html In Real Time On Browser Open It"