How can I inject a <script src="https://remote.com/"></script> element into my page, wait for it to execute, and then use functions that it defines?
FYI: In my case, the script will do some credit card processing in rare cases, so I don’t want to include it always. I want to include it quickly when the user opens up a change-credit-card-options dialog, and then send it the new credit card options.
Edit for additional detail: I do not have access to the remote script.
You could use Google Analytics or Facebook‘s method:
UPDATE:
Below is the new Facebook method; it relies on an existing script tag instead of
<head>:facebook-jssdkwith your unique script identifier to avoid it being appended more than once.