0

I've made a JavaScript code that is way to big for easy copy-paste. Therefore, it would be perfect to use jQuery's getScript to make it smaller.

I'm having a hard time to get it to work. I tought it maybe could be some spesial way to construct the .js. Here is what I got so far trying to figure it out.

javascript: 
(function() {
$.getScript("https://raw.githubusercontent.com/stianteien/forsvarsoversikt/master/test.js"); 
})()

Directed to this page: https://raw.githubusercontent.com/stianteien/forsvarsoversikt/master/test.js With the simple code:

alert("hello");

...my browser is sending an error:

Loading fail for this <script> with this source

How do I get this to work?

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223

1 Answers1

0

GitHub serves .js files as plain text. You can use $.get() or $.ajax(), create a <script> element and set the .textContent of the <script> element to the response, then append the <script> element to the document see Displaying pdf from arraybuffer

guest271314
  • 1
  • 15
  • 104
  • 177
  • Thanks! But I don't think it's the whole answer that I'm looking for. I want to run my github-script on any page. – Stian Teien Feb 11 '18 at 20:36