+ 6

How to get the source code(html) of a external website using JavaScript?

How to get the source code(html) of a external website using JavaScript? I googled it but couldn't find any satisfactory answers. I want something like url="https://www.google.co.in" function displayCode(url){ //returning the source code } How to do this?

28th Oct 2017, 12:23 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
5 Respostas
+ 6
Copying the code is not exactly what I want to do. But still, isn't there any way to access a file on a webpage(.html file also)?
28th Oct 2017, 1:01 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 4
Easy you thought of what am doing now root ur device then download root explorer file manager save any page which u want to view source code then back to RExplorer the search it and open it with sololearn or change its extension from .htm to .txt read it or edit it with wps office Done everything are you satisfied
1st Apr 2018, 8:04 PM
Scorpia Rising🎩
Scorpia Rising🎩 - avatar
+ 2
XHR and Fetch can retrieve arbitrary data. However, because of the security implications of retrieving source code from sites you do not own, these commands only participate in communications that set permissive headers. Sometimes administrators omit these headers for public resources like an API (a potential error), but finding permissive headers set on entire sites should be rare (not only is the default for everyone "don't permit", informed administrators may desire that).
28th Oct 2017, 1:31 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
It doesn't required root to do that. Just save the link if you are using Chrome, the extension will be .html and open it with notepad to see the source code.Then you can copy and past to code playground.Or run ditectly the .html file and open with SoloLearn //Maybe this is not exactly what you wanted Swapnil ‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌Srivastava but i hope it helps.
1st Apr 2018, 8:14 PM
Dovahkiin
Dovahkiin - avatar
+ 1
This is inherently impossible or difficult. See, your browsers' developer's console(s) are the only windows where code can be copied (in a garbled form). Retrieving code through the console is hard - without an API; even then, I don't think there will be APIs for browsers' most kept secret(s)... /* I can suggest a method of copying code. Where it actually takes effort: transcribe any block or modular interface as a <div> or <span> and text as <p> or <h1>. Use CSS layout rules, right: 0; left: 0; blahetc... Afterwards, you'll feel a tinge of... proudness and achievement. */ edit0 The files on a webserver may be accessed by copying the contents to a blank on your computer - a kindof cheaty method but valid - by having a file reader retrieve text or by downloading the file. Keep in mind that if a file is kept on a out-of-scope webserver, it's probably because they don't want people looking at them. But whatever: see if you can download the file through the console or at the target website (if it's a CDN).
28th Oct 2017, 12:34 PM
ghostwalker13
ghostwalker13 - avatar