简体   繁体   English

如何使用js在head标签中添加第三方url脚本和链接?

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

  1. one URL with script and other with stylesheet to be added in head tag using javascript?一个带有脚本的 URL 和另一个带有样式表的 URL 要使用 javascript 添加到 head 标签中?
  2. How can I add another third party script tag in head using javascript and display the code present in it after few seconds when page loads completely?如何使用javascript在head中添加另一个第三方脚本标签并在页面完全加载几秒钟后显示其中的代码?

Eg:例如:

        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"
        };
   

You can append elements like scripts or stylesheets using vanilla JavaScript您可以使用 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.

相关问题 使用 angular json + 基于环境在 head 标签中加载第三方 js - Load third party js in head tag using angular json + environment based 如何将脚本添加到<head>使用javascript标记 - How to add script to <head> tag using javascript 如何在Angular 6中运行第三方JS脚本 - How to run third party JS script in Angular 6 使用ZK:如何从Java将脚本添加到head标签? - Using ZK: How to add a script into the head tag from java? 如何在 Vue 中使用脚本标签加载第三方元素? - How can I load a third-party element using a script tag in Vue? 如何在 MkDocs 中将脚本添加到 head 标签? - How to add script to head tag in MkDocs? ASP.NET:如何(以编程方式)附加一个<script> tag, containing a link to .js, to <head>? - ASP.NET: How to (programmatically) attach a <script> tag, containing a link to .js, to <head>? 如何在特定脚本标记之后将脚本标记添加到头部 - How to add a script tag to the head section after a specific script tag 当路径始终转换为url时,如何使用script标记将指向npm包的链接添加到Django模板 - How to add link to npm package to a django template using the script tag when path is always converted to a url Next.js - 如何添加一个<link>里面的标签<head>带有文字 onload 属性字符串值? - Next.js - How to add a <link> tag inside the <head> with literal onload attribute string value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM