0

Is there a way to disable a script via a script. For example. Within my blogging platform I have the following added by default..

<script defer src="https://unpkg.com/@tryghost/portal@latest/umd/portal.min.js" data-ghost="https://www.packetflow.co.uk/"></script>

Is there a way to delete this or remove via javascript?

3
  • Have you tried to scan the page's DOM and remove it? or maybe rename the source file to something else? Commented Nov 19, 2020 at 19:48
  • Why do you need to remove it via JavaScript? If it's your webpage, can't you just remove it from the source? Commented Nov 19, 2020 at 19:48
  • is it actually added like this to the HTML? your blog doesn't minify and pack all the scripts together before serving? Commented Nov 19, 2020 at 20:07

1 Answer 1

2

Well, there is a certain level of ambiguity to this question or maybe i am just overthinking things.

Removing the Element from the DOM

var scriptElement = document.querySelector('script[data-ghost="https://www.packetflow.co.uk/"]').remove();

This removes the Script element from the DOM but, if the script runs and affects elements before this line is run, ITS EFFECTS CANNOT BE UNDONE. ... Since the script has a defer attribute, you could always make sure that your script with the remove line is located above it.

Removing the EFFECTS of the script

As aforementioned, this cannot be done after the script has been executed UNLESS you know eXactly what the script has affected in the DOM and are willing to reverse those effects with a countering script of your own.

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

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.