admin管理员组

文章数量:1332339

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.

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.

Share Improve this question asked May 6, 2011 at 11:54 nedge2knedge2k 1092 silver badges9 bronze badges 1
  • 1 possible duplicate of How do I load a javascript file dynamically? – Felix Kling Commented May 6, 2011 at 12:00
Add a ment  | 

2 Answers 2

Reset to default 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.

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

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

本文标签: javascriptInclude remote js file on the flyStack Overflow