T
Tereska
I want to delete script added before.
I'm adding script dynamically and i'm removing later.
Why it is still working?
I have something like this:
<html>
<head>
<title>JS Script Remove</title>
</head>
<body>
<a href="javascript:void(0)" onclick="javascript:showText()">Why it's
still working???!!!</a>
<script>
//making new script object
var objScript = window.document.createElement('script');
objScript.text = "function showText(){alert('I am still working!
WHY?');}"
objScript.type = 'text/javascript';
objScript.id = 'myScriptId';
//adding my script object to head element
var objHead = window.document.getElementsByTagName('head')[0];
objHead.appendChild(objScript);
//OK script added
alert(objHead.innerHTML);
//removing script from head
objHead.removeChild(objScript);
//script has gone
alert(objHead.innerHTML);
//nothing special in body
alert(document.body.innerHTML);
</script>
</body>
</html>
I'm adding script dynamically and i'm removing later.
Why it is still working?
I have something like this:
<html>
<head>
<title>JS Script Remove</title>
</head>
<body>
<a href="javascript:void(0)" onclick="javascript:showText()">Why it's
still working???!!!</a>
<script>
//making new script object
var objScript = window.document.createElement('script');
objScript.text = "function showText(){alert('I am still working!
WHY?');}"
objScript.type = 'text/javascript';
objScript.id = 'myScriptId';
//adding my script object to head element
var objHead = window.document.getElementsByTagName('head')[0];
objHead.appendChild(objScript);
//OK script added
alert(objHead.innerHTML);
//removing script from head
objHead.removeChild(objScript);
//script has gone
alert(objHead.innerHTML);
//nothing special in body
alert(document.body.innerHTML);
</script>
</body>
</html>