0

I don't think its possible, but I wanted to check with the 'experts'.

I only have CSS access to a site, is there anyway using CSS I can force in a JS file?

Thanks.

Matt Cowley
  • 2,164
  • 2
  • 18
  • 29
  • @MatthewCowley Do you want to include a file or would simply running a script sufficient? – idmean Feb 28 '16 at 11:06
  • @idmean All I want to do is be able to run JS on the site, but I only have CSS access. So running a script would be fine. – Matt Cowley Feb 28 '16 at 11:07
  • @idmean Already been mentioned in an answer, I hadn't seen this when i submitted the question, it hadn't come up. – Matt Cowley Feb 28 '16 at 11:11
  • @MatthewCowley That's an automatic comment because I voted to close this as a duplicate. – idmean Feb 28 '16 at 11:12
  • @idmean Ah. Well I've my answer anyway it seems, which is no. But when I submitted the question, the 'duplicate' didn't come up. – Matt Cowley Feb 28 '16 at 11:17

2 Answers2

0

It looks, like your question is a duplicate of Import JavaScript files with CSS.

According to related post, it is not possible to load js file using @import rule inside css file.

CSS file can trigger loading following resources:

  • other css files
  • images
  • fonts

Any attempt to return js script in response to css stylesheet request, will result in css parse errors in the browser.

Community
  • 1
  • 1
0

Bad idea, but you can use behavior (Work on IE9)

<html>
<head>
    <style>
        body {
            behavior: url('script.htc');
        }
    </style>
</head>
<body>
</body>
</html>

And "script.htc":

<script type="text/javascript">
    alert('hello world!');
</script>
MBN
  • 1,006
  • 7
  • 17