我有一个页面,我无法访问它的 obvius 站点。我想删除带有内容的脚本 html 标签。现在我有这个但没有用。我正在像编码一样使用用户脚本!
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 我只是想知道是否还有其他方法。但正如我所见,唯一的是主机文件:)
最佳答案
我认为这行不通,因为加载的脚本已经运行了。
也就是说,您可能想要这样的东西:
$('script').each(function() {
if (this.src.substring(0, 31) === 'http://storing.com/javascripts/') {
$(this).remove();
}
});
不可能匹配<script>
基于 .html()
输出的标记因为它只返回元素的内容,而不是外部 <script>
元素或元素的属性。
关于javascript - 使用 jquery 删除具有特定内容的脚本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12426432/