js: Load html of a page from a different domain

后端 未结 3 1461
余生分开走
余生分开走 2021-01-07 12:16

I was wondering how can I load HTML, which is hosted on a different domain?

I am using JavaScript, and want to create a bookmarklet that will enable me to parse the

3条回答
  •  死守一世寂寞
    2021-01-07 13:07

    You can make cross-domain requests from localhost, but if you plan to deploy this code to a server, it's not going to work. Since you are developing a bookmarklet, I think you can do this.

    You'll need to use AJAX to get the remote HTML.

    The jQuery library makes this task as simple as this...

    $.get("http://www.google.com", function(html) { alert(html); });
    

提交回复
热议问题