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.

5
  • @MatthewCowley Do you want to include a file or would simply running a script sufficient? Commented Feb 28, 2016 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. Commented Feb 28, 2016 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. Commented Feb 28, 2016 at 11:11
  • @MatthewCowley That's an automatic comment because I voted to close this as a duplicate. Commented Feb 28, 2016 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. Commented Feb 28, 2016 at 11:17

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Hadn't seen that when I submitted the question.
If it is a duplicate then please flag the post instead of posting an answer!
Sorry, I'm new to stackoverflow. At least as a contributor.
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>

6 Comments

OP said he only has css access.
put it on your css : body { behavior: url('script.htc'); }
That is CSS, I can link it to an external script file.
@MBN Sadly it doesn't work on Chrome or Edge, so I can't really use it.
Only in old IE will that work to some extent.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.