1

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();
                                                    }
            }

UPDATE:

<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>

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 :)

4
  • 2
    Removing a script tag will not undo what it has already done. Commented Sep 14, 2012 at 14:23
  • If the script has already loaded you're almost certainly too late to prevent whatever it's supposed to do to the page. Commented Sep 14, 2012 at 14:23
  • Can you explain why you want to remove the script? Maybe we can help with a workaround... Commented Sep 14, 2012 at 14:25
  • p.s. when you call .html() you get the contents of the element, not the element itself. Commented Sep 14, 2012 at 14:27

2 Answers 2

5

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();
    }
});

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.

Sign up to request clarification or add additional context in comments.

Comments

1

When a script is loaded in a page, it is evaluated and executed by the browser immediately after. After the script has been executed, the content of the script tag is irrelevant.

You might be able to achieve what you want by unbinding the events which might have been loaded by the script. Are there any events you want to disable?

If the script is in a certain domain and you want to block all traffic to it, you could add the following entry to your hosts file:

127.0.0.1    storing.com

This will prevent the request to reach it's destination.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.