Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  90] [ 2]  / answers: 1 / hits: 55257  / 13 Years ago, wed, february 22, 2012, 12:00:00

how can I remove my appended script because it causes some problems in my app.



This is my code to get my script



var nowDate = new Date().getTime();
var url = val.redirect_uri + notify.js?nocache= + nowDate + &callback=dummy;
var script = document.createElement('script');
script.src = url;
document.body.appendChild(script);


Then I have an auto load function, that causes to create another element script.



I want to get rid of the previous element that was appended before another element is added.


More From » append

 Answers
48

I did some more tests, and before you'll get a correct answer to your question (hope there is a one) you can try this:



<button onclick=foo()>ShowHTML</button>
<script>
(function foo(){
var b=function moo(){
var c=document.getElementsByTagName('script');
alert(document.body.innerHTML);
c[0].parentElement.removeChild(c[0]);
alert(document.body.innerHTML);
}
var a=setTimeout(b,1000);
b=null;
})();
foo=null;
</script>


This is just a test code, but it contains an idea, how you possible could solve the problem. It removes <sript> from the DOM, and the last line destroys all functionality of the script.



(The code also has a little detail, which shows, that setTimeout will do eval(), no matter how it is argumented...?)


[#87305] Monday, February 20, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryder

Total Points: 473
Total Questions: 110
Total Answers: 91

Location: Northern Ireland
Member since Mon, Nov 14, 2022
2 Years ago
ryder questions
Tue, Nov 30, 21, 00:00, 3 Years ago
Fri, Jul 23, 21, 00:00, 3 Years ago
Tue, Jun 15, 21, 00:00, 3 Years ago
Thu, May 20, 21, 00:00, 3 Years ago
;