0

In PHP we have a function called file_get_contents where it gets the content of a website and turns it into a string, but what about JavaScript? What is JavaScript's equivalent to file_get_contents? Is there one?

$string = file_get_contents("http://example.com/");

I do NOT have access to PHP, I'm using tampermonkey to edit this code, so it's JavaScript ONLY.

frosty
  • 2,402
  • 7
  • 29
  • 65

1 Answers1

1

For node, there's http.get().

For modern browsers, there's fetch().

For older browsers, there's XHR.

Joseph
  • 113,089
  • 28
  • 177
  • 225