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

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip