1

If file1 uses .load(file2) and If file2 has Javascript/Jquery initialization code. Is there a way to initialize the code inside file2 by file2 when loaded into a container in file1 by file1?

$(document).ready(... doesn't quite work for this. Remember the code should be inside file2 (the file being loaded should initialize it's own js, is this possible?)

I hope this makes sense..

2 Answers 2

1

Script tags in the loaded code will be run if:

  • The tags have no "type" attribute, or of the value of the "type" is "text/javascript" (exactly)
  • The ".load()" call is a pure URL, and not a URL + a selector, like "$('.foo').load(url + ' .stuff')`
Sign up to request clarification or add additional context in comments.

Comments

0
$(document).ready(function(){
  myImage = new Image()
  myImage.src = "/path/to/file2.js" 
})

I hope this code will helps you.

1 Comment

that won't work inside the file being loaded.. I can call load(url,init) like this, but i cannot just call load(url) and have the url init its own code.

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.