-1

How to get given URL's page source in Javascript.

Suppose i give window.open("https://www.google.co.in"); then it should go to above URL and take page source of google.com which can be save in file. I am using JS in HTML.

user3464130
  • 21
  • 1
  • 3
  • 1
    This can't be done in javascript. You need to do this on the server. – Smeegs Jul 10 '14 at 14:30
  • I think a better question is **why** do you want to do this? If I'm understanding correctly, it sounds like you want to get the source of the page that your user is attempting access and replacing it with a copy you've pulled yourself. But **why??** This is what the browser is designed to do. – esqew Jul 10 '14 at 14:33
  • @ Smeegs how to do it using other lang with the help of JS – user3464130 Jul 14 '14 at 07:46
  • @esqew actually i wanted to find out all links in given page a save them in a file – user3464130 Jul 14 '14 at 07:48
  • window.open("https://www.google.co.in"); var sourceObj = "view-source:" + window.location.href; – user3464130 Jul 14 '14 at 07:50

1 Answers1

0

I you want a cross-domain solution (like your example for google), you can't.

See How to get html source code from external url

Community
  • 1
  • 1
Nicolas Henrard
  • 843
  • 8
  • 19