2

Is there a simple way to include a remote js file on the fly (in an onclick function)?

The "verify" onclick event for our ssl site seal requires a code include from the vendor. Trouble is, it slows loads times. So I extracted the function from their js and hosted it locally - but they change the request params from time to time so I have to manually edit the js.

It would be nicer if I could just include the remote file when someone clicks the site seal.

TIA.

nedge2k
  • 109
  • 2
  • 9
  • 1
    possible duplicate of [How do I load a javascript file dynamically?](http://stackoverflow.com/questions/5235321/how-do-i-load-a-javascript-file-dynamically) – Felix Kling May 06 '11 at 12:00

2 Answers2

3

If you are using jQuery you can use $.getScript

Description: Load a JavaScript file from the server using a GET HTTP request, then execute it.

Timon. Z
  • 681
  • 3
  • 9
  • thanks but i want to use as little js as possible and don't want to load up any other libraries such as moo tools or jquery. – nedge2k May 06 '11 at 12:20
  • So just look at Felix Kling comment : http://stackoverflow.com/questions/5235321/how-do-i-load-a-javascript-file-dynamically – Timon. Z May 06 '11 at 12:22
2

You can use the createElement() and add it to the DOM. Please see the below document.

http://www.hunlock.com/blogs/Howto_Dynamically_Insert_Javascript_And_CSS

James Jithin
  • 10,183
  • 5
  • 36
  • 51