0

I want to read the html content from given url, but it shows same origin error(I know about this error). So I have tried different method. Open a new window and open the website to that window and read the content from that window, but not work please help me.


Note: This is for my cordova application!

I tried like below

var myWindow=window.open('http://www.google.com','','width=200,height=100');
//myWindow.document.write("<p>This is 'myWindow'</p>");
alert(myWindow.innerHTML);
myWindow.document.close();
Mimouni
  • 3,564
  • 3
  • 28
  • 37
Asith Raj
  • 63
  • 1
  • 1
  • 10

1 Answers1

5
$.get( "http://www.google.com/", function( data ) {
    console.log(data);     
});

With help of jQuery, you can get html content of specified URL. Replace your desired URL with "http://www.google.com/". It won't give error in real device or Emulator. But if you will check in Browser then it will give error of CORS.

Regards

Hardik Vaghani
  • 2,163
  • 24
  • 46
  • I tried in browser console window, over stackoverflow but it show "No 'Access-Control-Allow-Origin'" error – Asith Raj Jul 14 '16 at 12:39
  • Yes it will always give CORS error so you can not test in browsers try in real device. – Hardik Vaghani Jul 14 '16 at 12:40
  • @AsithRaj: just for information, there is a way to simulate in chrome browser, by activating some fonctions here : "chrome://flags/". but this part is very advanced in fonctionalities. so you shouldn't activate or disactivate a function only if you now what you are doing. :) – Mimouni Jul 15 '16 at 09:53
  • Yes i wouldn't recommend that too. – Hardik Vaghani Jul 15 '16 at 09:58