Using Third Party JS in Ionic
By Mike Roberts
When you use products like Google Analytics, Stripe or Zendesk and they donβt have a library on npm to assist with using them in javascript then they can be a pain to get working in Cordova/Ionic apps. Usually their instructions have something like this in them:
<script type="text/javascript">
var js = document.createElement('script');
js.src = '//website.com/super/secret/jsfile.js';
document.body.appendChild(js);
</script>
The trick is that little //
in the beginning of the script source. What that does is match the protocol of the currently loaded website, which in the case of a cordova app is file://
which renders their instructions useless. Easy fix, since we should be loading everything over https these days anyways, is to just change the script source and add https before those double slashes, and now your third party javascript magically works in your app.