Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate an "include_once" for jQuery

I have created a simple page that use jQuery, so include jquery.min.js.

But I have to insert an iFrame in the same page (and no, unfortunately I can't use anything else) that include a different versione of jquery.min.js.

How can I force the browser to include only one of those two version (like an include_once in php)?

Thank you!

like image 454
Marco Pace Avatar asked Oct 25 '11 10:10

Marco Pace


1 Answers

Not tested but at the end of your page, just before </body> tag, you can add this:

<script>
  window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

This checks if jQuery is available or not, if not it will add one dynamically from path specified.

like image 184
Sarfraz Avatar answered Sep 24 '22 20:09

Sarfraz