How to add external scripts?
-
I tried loading it like this:
mounted() { var script = document.createElement("script"); script.src = "https://platform.twitter.com/widgets.js"; script.type = "text/javascript"; var head = document.getElementsByTagName("head")[0]; head.appendChild(script); },
but that doesn’t work - it doesn’t load.
(I used the html from here except for the script tag.)
I also tried it with “vue-twitter” (like it and with a boot-file) which uses VueScript2.load but it says:
"TypeError: window.twttr is undefined"
so it doesn’t properly load that script.I could be overlooking something trivial here. NoScript shows a request to twitter, I hope it’s not a CORS issue - I’m testing with
quasar dev
and Firefox and would expect a CORS-related error message if it was.How to load external (libraries/)scripts?
-
<script> // ############################################## // função loadScript para carregar script externo // Lazy Loading Scripts // ############################################## function loadScript (url, classe) { let isLoaded = document.querySelectorAll(classe) // verifica se o script já foi caregado if (isLoaded.length > 0) { // não faz nada... } else { let myScript = document.createElement('script') myScript.src = url myScript.className = classe document.body.appendChild(myScript) } } loadScript('statics/directpayment.js', 'insert-script') // ############################################## export default { ...
-
@altenirgama said in How to add external scripts?:
classe
What is this parameter for / What does it do?
-
This post is deleted! -
@dobbel just to know if the script has already been loaded and not to load again by duplicating, can give another name