开发者

Include remote js file on the fly?

开发者 https://www.devze.com 2023-03-04 14:57 出处:网络
Is there a simple way to include a remote js file on the fly (in an onclick function)? The \"verify\" onc开发者_Go百科lick event for our ssl site seal requires a code include from the vendor. Trouble

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

The "verify" onc开发者_Go百科lick 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.


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.com/blogs/Howto_Dynamically_Insert_Javascript_And_CSS

0

精彩评论

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