使用jquery删除具有特定内容的脚本标记 [英] Removing a script tag with a specific content using jquery
问题描述
我有一个页面,我无法访问其obvius网站。我想删除带有内容的脚本html标记。现在我有这个但是没有用。我正在使用像编码这样的用户脚本!
I have a page that i dont have access to its an obvius site. I would like to remove a script html tag with a content. For now i have this but is not working. I am using userscripts like coding!
function main(){
var def = $('script[type="text/javascript"]').html();
$('script[type="text/javascript"]').each(function() {
if (def == 'document.write("<scr"+"ipt type=\'text/javascript\' src=\'http://storing.com/javascripts/"+(new Date()).getTime()+"/3e155555e1b26c2d1ced0f645e_1_1.js\'></scr"+"ipt>")')
$('script[type="text/javascript"]').remove();
}
}
更新:
<script type="text/javascript">document.write("<scr"+"ipt type='text/javascript' src='http://somedomain.com/javascripts/"+(new Date()).getTime()+"/3e1a0cd37f25a6e1b26c2d1ced0f645e_1_1.js'></scr"+"ipt>")</script>
这是我要删除的整个脚本...它插入一个我现在正在删除的div我只是想知道是否有任何其他方法。我看到的只是BUt是hosts文件的东西:)
This is the whole script what i want to remove... it inserts a div that i am removing right now i just wanted to know if there is any other method. BUt as i see the only is the hosts file thing :)
推荐答案
我不相信这会有效,因为加载的脚本已经运行了。
I don't believe this will work, since a loaded script will already have run.
那说,你可能想要这样的东西这个:
That said, you probably want something like this:
$('script').each(function() {
if (this.src.substring(0, 31) === 'http://storing.com/javascripts/') {
$(this).remove();
}
});
无法匹配< script>
标签基于 .html()
的输出,因为它只返回元素的内容,而不是外部< script>
元素和元素的属性。
It's impossible to match the <script>
tag based on the output of .html()
because that only returns the contents of the element, and not the outer <script>
element nor the element's attributes.
这篇关于使用jquery删除具有特定内容的脚本标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!