簡體   English   中英

如何使用js在head標簽中添加第三方url腳本和鏈接?

[英]How to add third party url script and link in the head tag using js?

  1. 一個帶有腳本的 URL 和另一個帶有樣式表的 URL 要使用 javascript 添加到 head 標簽中?
  2. 如何使用javascript在head中添加另一個第三方腳本標簽並在頁面完全加載幾秒鍾后顯示其中的代碼?

例如:

        var RequestURL = '';
        function onWindowClosed(obj) {
        /*This is the function where you need to handle callback object based on various codes
          If the event name passed by you is not matched with the returned one then you can call the logout functionality, as there are some error occured inside the WEB.
        */
        console.log("callback event : " + JSON.stringify(obj));
        if (obj.event_name === event_name) {
            /*your event is returned here.*/
            console.log("successfully returned: " + obj.message);
        } 
        else {
            /*handle other event names here. It may be any 
            unknownEvent,init,capture,initiateAndCapture */
            console.log("event not returned");
        }
        }
        var userDetails= JSON.stringify({
            "appId": ",  
            "customerId": "", 
            "user_type" : "", 
            "name" : "", 
            "transaction_date" : "", 
            "city": "" //optional
            // any other parameters on which the response needs to be analyzed should be included here.
        });

        var params= {
            "event_name":"myEvent"
        };
   

您可以使用 vanilla JavaScript 附加腳本或樣式表等元素

 var script = document.createElement("script"); script.setAttribute("src", "https://script.example.com/script.js") // Replace with your script link var head = document.querySelector("head") head.appendChild(script)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM