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)

3
  • 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 ? Commented Jan 1, 2021 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. Commented Jan 1, 2021 at 12:06
  • Try fetch if your script is in browser, try http.request if you want it in Node Commented Jan 1, 2021 at 12:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.