-3

In the html file:

<html>
  <head>
     <script type="text/javascript" src="/images/files/js/callback.js"></script>
  </head>
</html>

in the callback.js file:

$(document).ready(function() {
document.write('<script type="text/javascript" src="/images/files/css/style.css" ></script>');
document.write('<link src="/images/files/js/core.js">');
}

About some reason it will add al the text of the callback.js file into my page but won't load the style.css and the core.js, So when I visit the page the elements of callback.js will be in the head element but they don't work on the page, so I have a page without css and js

second thing I want to achieve is that if it has load all the content of the callback.js it will remove the link to callback.js so that file isn't visible anymore

The reason I want to do this is in javascript/jquery is because I hate php and I've a lot of pages with exactly the same links in it.

3 Answers3

1
$(document).ready(function() {

   /* creating script and link elements */

   var style = $('<link />', {
       'href': '/images/files/css/style.css',
       'rel': 'stylesheet'
   });
   var core  = $('<script />', { 
       'src': '/images/files/js/core.js'
   });


   /* append style and core */

   var head  = $('head');
   style.appendTo(head);
   core.appendTo(head);

});
Fabrizio Calderan loves trees
  • 109,094
  • 24
  • 154
  • 160
0

Change

document.write('<script type="text/javascript" src="/images/files/css/style.css" ></script>');

to,

document.write('<link rel="stylesheet" type="text/css" href="/images/files/css/style.css" >');
Sarvap Praharanayuthan
  • 3,673
  • 6
  • 43
  • 65
0

You write :

document.write('<script type="text/javascript" src="/images/files/css/style.css" ></script>');

You are trying to include a CSS file in a script tag. Use instead :

document.write('<link rel="stylesheet" href="/images/files/css/style.css"/>');
Gwenc37
  • 2,038
  • 7
  • 16
  • 22