1

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,559
  • 8
  • 37
  • 73

1 Answers1

2

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

For modern browsers, there's fetch().

For older browsers, there's XHR.

Joseph
  • 117,725
  • 30
  • 181
  • 234