I am writing script tags from the console to my test.html file:
test.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery load() Demo</title>
</head>
<body>
<p>nothing</p>
</body>
<script>
</script>
from console:
var script = document.createElement('script');script.src = "https://code.jquery.com/jquery-3.6.4.min.js";document.getElementsByTagName('head')[0].appendChild(script); var script2 = document.createElement('script');script2.type="text/javascript"; script2.src="http://Localhost:Dropbox/prog/jquery/js/ravaf.js"; document.head.appendChild(script2);
resulting in this in my test.html file:
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script type="text/javascript" src="http://Localhost:Dropbox/prog/jquery/js/ravaf.js"></script>
I can access jquery functions from the console but not the javascript from ravaf.js
ravaf.js:
var t2=100;
function t3() {
alert("t3");
}
const t4="front 242";
var "f1"=43334;
why can’t I use any of the functions/variables (from ravaf.jf) in my console?
2
Answers
So I kinda figured it out. Note that the javascript is injected after the page has loaded but my exernal file is loaded and the functions are there to use in the console. note that the path was wrong and also the append. here is the correct code:
You have a syntax error in your code. If you fix that, it will work