Home > Software engineering >  Running javascript file hosted on a different website
Running javascript file hosted on a different website

Time:09-30

I am trying to run a JavaScript file I hosted on GitHub.

Its a snow falling script from This Site

This code is not working.

<html>
<head>
<title>DHTML SnowStorm: Basic Example</title>
<script type="text/javascript" src="https://raw.githubusercontent.com/GH0STH4CKER/PROJECTS/master/snowfall.js"></script>
</head>
<body style="background:#6699cc;font:100 1.75em helvetica neue, helvetica,arial,verdana,sans-serif;color:#fff">
<h1 style="font-size:2em;margin:0px;font-weight:100">Example SnowStorm page</h1>
<p>
 A single Javascript reference in the &lt;head&gt; tag is required for SnowStorm to work.
</p>
<p>
 View the source of this page for reference.
</p>

</body>
</html>

Output : No Snow Falling Expected : Snow falling

How can I run this .js file in my website ?

Update - Got this error in console :

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://raw.githubusercontent.com/GH0STH4CKER/PROJECTS/master/snowfall.js with MIME type text/plain.

CodePudding user response:

[ ~ ] ➜  curl -I https://raw.githubusercontent.com/GH0STH4CKER/PROJECTS/master/snowfall.js | grep -i Content-Type
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0 21184    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
content-type: text/plain; charset=utf-8

The server you are using, raw.githubusercontent.com, tells the browser that the file contains plain text.

Since it has been told that it isn't JavaScript, the browser doesn't execute it.

Use a hosting service designed for general purpose hosting instead.

CodePudding user response:

This is not possible. You get a CORS (Cross-Origin Resource Sharing) error. This means you cant access the data on another domain.

More info at: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Maybe try downloading the file and put it in the website folder?

Hope I could help, beldrnl

  • Related