admin管理员组

文章数量:1295909

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('','','width=200,height=100');
//myWindow.document.write("<p>This is 'myWindow'</p>");
alert(myWindow.innerHTML);
myWindow.document.close();

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.','','width=200,height=100');
//myWindow.document.write("<p>This is 'myWindow'</p>");
alert(myWindow.innerHTML);
myWindow.document.close();
Share Improve this question edited Jul 14, 2016 at 12:15 Mimouni 3,6303 gold badges31 silver badges37 bronze badges asked Jul 14, 2016 at 11:15 Asith RajAsith Raj 631 gold badge2 silver badges10 bronze badges 5
  • I would try and use a Cordova API – alex Commented Jul 14, 2016 at 11:16
  • @alex Can you tell any cordova plugin name for this. – Asith Raj Commented Jul 14, 2016 at 11:17
  • If you want to get content from url, i think you should use ajax $.get(...); – Mimouni Commented Jul 14, 2016 at 11:21
  • @IlyasMimouni it shown same origin error, like google... – Asith Raj Commented Jul 14, 2016 at 11:23
  • @AsithRaj: you have to configure the server by adding some code php, take a look on the anwser here : stackoverflow./questions/23665056/… – Mimouni Commented Jul 14, 2016 at 11:25
Add a ment  | 

1 Answer 1

Reset to default 5
$.get( "http://www.google./", 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./". 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

本文标签: get the html content from url using jquery or javascriptStack Overflow