-1

How can I execute my JavaScript after the HTML and other JavaScript has been parsed, but not wait on any other resources (images, stylesheets, etc.)? My JavaScript, which is a user script / Chrome extension, automates clicks on buttons which require other JavaScript to manipulate variables, but don't require other resources.

I am aware of the events load and DomContentLoaded. In my testing, DomContentLoaded does not wait for all of the JS to be parsed. load waits for everything, which is what I'm using now, but not what I want.

11
  • Create a function with your JS, and call it at the end of the other JS. Commented Jun 28, 2018 at 23:04
  • @VictoriaRuiz I don't have control over the other JS. Commented Jun 28, 2018 at 23:09
  • put your script in a script tag after all the other script tags Commented Jun 28, 2018 at 23:51
  • @JaromandaX I don't have control over the html either. This is a user script / Chrome extension. I will clarify that in the question. Commented Jun 28, 2018 at 23:53
  • so, is it a user script or a chrome extension? the two are different - user script (tampermonkey) - tampermonkey.net/documentation.php#_run_at are your only options - as for extension - I'm sure there's documentation available Commented Jun 29, 2018 at 0:06

1 Answer 1

0

A tricky way to do it: use load and insert a <script> at the end of the document, and put your codes into it.

I believe this WILL work. The point is, browsers parse and run the <script> one by one, in a strict order. So when the browsers get to your <script>, it means the other <script>s have been parsed and executed, but all other resources might not return. I think this is what you want?

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.