0

I have a strange problem related to inline javascript and css. On my localhost (WAMP server 2.2) everything works as it should (inline styles and scripts are used and working properly), but on a production server (shared hostgator server) inline scripts are completely overlooked by browsers. If I simplify and give you an example of what I mean:

<html>
   <head>
      <!--normal head includes, jquery, styles and other stuff -->
   </head>
   <body>
   <script type="text/javascript">
      jQuery(document).ready(function() {
         alert("test");
      });
   </script>
   <style type="text/css">
      a { color:red; }
   </style>
   <a href="http://www.google.com">Some link</a>
   </body>
</html>

On localhost "Some link" will be colored red and an alert will popup. But on the production server none of that happens.

What kind of settings (I assume this is security related) on the server are making this possible and how can I change it so that inline scripts and styles will be used?

Dairo
  • 822
  • 1
  • 9
  • 22
Janez
  • 2,336
  • 5
  • 25
  • 37

1 Answers1

0

Do it programmatically like this:

$(document).ready(function(){
    var head = document.getElementsByTagName('head')[0],
    style = document.createElement('style'),
    css = 'a { color: red }';

    style.type = 'text/css';

    if (style.styleSheet) {
        style.styleSheet.cssText = css;
    }
    else {
        style.appendChild(document.createTextNode(css));
    }
    head.appendChild(style);
});

I hope it helps. PS: good practice: load scripts before body closing tag. Only load css in head tag.

Gabriel Burciu
  • 123
  • 2
  • 6
  • thanks for suggestion. But don't you agree that this should be working without appending it to the head (additional hack). I mean I know about [this](http://stackoverflow.com/questions/1362039/style-and-script-tags-in-html-body-why-not#1362192) but browsers should still use it – Janez Jan 20 '14 at 07:59