开发者

Loading an external JavaScript file after web form has loaded

Is it possible to load in an external JavaScript file on the click of a button, without using JQuery? The idea is so the forms load time is reduced by not having to load in the file straight away, as it is not entirely necessary unless something 开发者_运维问答is requested by the user. I understand my description is probably not the best, but if you require any more information then please ask.

Thank you for your help.


Sure; just as you can use javascript to create a new <div> tag and append it to the page, you can do the same with a <script> tag:

  var scr=document.createElement('script')
  scr.setAttribute("type","text/javascript")
  scr.setAttribute("src", "myNewJavascript.js")
  document.getElementsByTagName("head")[0].appendChild(scr)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜