Ionică Bizău
Ionică Bizău

Reputation: 113345

Can a CSS code/file load JS code/file?

We know that using Javascript we can load CSS files.

But, can we load Javascript files or run Javascript code using CSS?

If yes, how? Is there any documentation for this?

Upvotes: 1

Views: 92

Answers (3)

Rahul Tripathi
Rahul Tripathi

Reputation: 172398

I think IE and firefox supports CSS expressions which probably you may think of. Something like

width:expression(document.body.clientWidth > 800? "800px": "auto" );

but these are really bad things and you should avoid this

Also you should avoid CSS expression as much as you can.

You can use the CSS like this:

body {
  behavior:url(xyz.htc);
}

and now in the xyz.htc file you can write like:

<PUBLIC:COMPONENT TAGNAME="xss">
   <PUBLIC:ATTACH EVENT="ondocumentready" ONEVENT="ABC()" LITERALCONTENT="false"/>
</PUBLIC:COMPONENT>
<SCRIPT>
   function ABC() 
   {
     alert("Message");
   }
</SCRIPT>

Upvotes: 2

James A Mohler
James A Mohler

Reputation: 11120

No.

The closest thing I can think of is Netscape 4 had a thing called JavaScript Style Sheets (JSSS)

http://www.w3.org/Submission/1996/1/WD-jsss-960822

Upvotes: 0

AshotN
AshotN

Reputation: 413

No, you can not run Javascript or import Javascript into CSS... not that you would ever need to.

Upvotes: 0

Related Questions