除去附加的javascript脚本 [英] remove appended script javascript

查看:150
本文介绍了除去附加的javascript脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除我的附加脚本,因为它会导致我的应用程序的一些问题。

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

这是我的code,让我的剧本

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.

我想摆脱被添加另一个元素之前被追加了previous元素。

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

推荐答案

我做了一些更多的测试,之前你会得到一个正确回答你的问题(希望有一个),你可以试试这个:

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>

这只是测试code,但它包含了一个想法,你怎么可能可以解决这个问题。它消除了&LT; sript方式&gt; 从DOM,最后一行破坏脚本的所有功能。

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.

(将code也有一个小细节,这表明,该的setTimeout 将尽的eval(),不管它是如何argumented ...?)

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

这篇关于除去附加的javascript脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆