For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Friday, April 07, 2017

Load JavaScript with extra tags for example data-shr-siteid or data-sumo-site-id

Load Load JavaScript with extra tags for example data-shr-siteid or data-sumo-site-id

You can use below code.

<script>
 var loadScript = function(location, callback){
   var fileRef = document.createElement('script');
   fileRef.setAttribute('type','text/javascript');

   if (callback) {
     if (fileRef.readyState) {  // IE
       fileRef.onreadystatechange = function() {
         if (fileRef.readyState == 'loaded' || fileRef.readyState == 'complete') {
           fileRef.onreadystatechange = null;
           callback();
         }
       };
     } else {  // Non-IE
       fileRef.onload = function(){
         callback();
       };
     }
   }

   fileRef.setAttribute('src', location);
   fileRef.setAttribute('data-shr-siteid', '<?php echo $api_key; ?>');
   fileRef.async = true;
   document.head.appendChild(fileRef);
 };

function doss() {
    var surl='<?php echo ShareaholicUtilities::asset_url('assets/pub/shareaholic.js') ?>';
 loadScript(surl, function() {
   // CALLBACK - code that does something with the data returned by loading the script
 });
}
setTimeout("doss();",6000);
</script>
 



Share:

0 comments:

Post a Comment

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip