Forum Moderators: open

Message Too Old, No Replies

CSS as response from AJAX

         

torbol

7:51 am on Jul 2, 2008 (gmt 0)

10+ Year Member



hello, i have a problem with interpreting css in IE browser as response from ajax. Is it posible, IE not support this solution? In example,
Firefox and other inteligent browsers has no problem ;) How can i resolve my problem?

torbol

10:21 am on Jul 2, 2008 (gmt 0)

10+ Year Member



Ok, i found solution this problem. Ajax can return javascript which dinamicaly loading css file. Its working in all browsers.

Example:

var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = 'FireFox.css';
cssNode.media = 'screen';
headID.appendChild(cssNode);

eelixduppy

4:07 pm on Jul 2, 2008 (gmt 0)



Nice. Glad you got it working.

Thanks for sharing :)

httpwebwitch

5:30 pm on Jul 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also try the most excellent Mootools CSS Asset method [docs.mootools.net]

var myCSS = new Asset.css(source[, properties]);

example:

var myCSS = new Asset.css('/css/myStyle.css', {id: 'myStyle', title: 'myStyle'});

torbol

3:12 pm on Jul 3, 2008 (gmt 0)

10+ Year Member



httpwebswitch, you are right. this is shorter and most elegant solution, but need mootools framework:) In our project we have a prototype framework and it's not good idea to include next:)

So, thnx for a help. I will study mootools framework and maybe i will use it in my next project:) I was hear that it is lighter than prototype and has quite good functionality:)

kceleb9

9:14 pm on Jul 6, 2008 (gmt 0)

10+ Year Member



I do this regularly with jQuery - but just return a JSON hash from the server.

You can then use the $.css() to apply the JSON hash (of CSS name/value pairs) to whatever you are trying to style.