No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to add external scripts?

    Help
    external script twitter
    3
    5
    1025
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mYnDstrEAm
      mYnDstrEAm last edited by mYnDstrEAm

      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?

      1 Reply Last reply Reply Quote 1
      • A
        altenirgama last edited by altenirgama

        <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 {
        ...
        
        dobbel 1 Reply Last reply Reply Quote 1
        • dobbel
          dobbel @altenirgama last edited by

          @altenirgama said in How to add external scripts?:

          classe

          What is this parameter for / What does it do?

          A 1 Reply Last reply Reply Quote 0
          • A
            altenirgama last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • A
              altenirgama @dobbel last edited by altenirgama

              @dobbel just to know if the script has already been loaded and not to load again by duplicating, can give another name

              1 Reply Last reply Reply Quote 0
              • First post
                Last post