3

I want to get source code of specific URL in JavaScript.

I can get source code of current web page with this code:

document.documentElement;

But I don't know how can I get source code of specific URL.

(I want to use documentElement anyway)

Programmer
  • 365
  • 2
  • 9
  • 1
    you can use fetch, and e= createElement, than e.innerHTML = fetch response, and than the e will contains your source (will work only if cors is enabled), can you explain more ? – phoenixstudio Jan 01 '21 at 12:05
  • `documentElement` gives you DOM element, it isn't source code, and can't get you anything not relating to the current document. – Quentin Jan 01 '21 at 12:06
  • Try [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) if your script is in browser, try [http.request](https://nodejs.org/api/http.html#http_http_request_url_options_callback) if you want it in Node – kiranvj Jan 01 '21 at 12:10

0 Answers0