开发者

Reference JS file in JS file

开发者 https://www.devze.com 2023-03-28 01:08 出处:网络
I have a Js function 开发者_开发知识库that I would like to: Reference another js file Pull a function out.

I have a Js function 开发者_开发知识库that I would like to:

  1. Reference another js file
  2. Pull a function out.

I would like to do this JS side and not reference on the actual page as I need this process to happen dynamically.


var h = document.getElementsByTagName('head')[0],
    s = document.createElement('script');

s.type = 'text/javascript';
s.onload = function () { document.getElementById('hello').innerText = h.innerText; };
s.src = 'http://html5shiv.googlecode.com/svn/trunk/html5.js';
h.appendChild(s);

see: http://jsbin.com/uhoger


If you're working with the browser, jQuery has an helper function for it, $.getScript.


The only option I can think of is to dynamically insert a new script tag into the page targeting your desired script from your initial javascript. Just have your initial script insert the new <script> tag on load, or upon request and then test for availability.

0

精彩评论

暂无评论...
验证码 换一张
取 消