In JavaScript, is there a way to get source code of a page given its URL? Kind of equivalent to PHP's file_get_contents()
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can just download from a URL through XMLHttpRequest (or jQuery's ajax
):
$.get(
'yourfile.js',
function(data) {
// The source code is in data
}
);
回答2:
How about this: http://phpjs.org/functions/file_get_contents:400 ?
回答3:
I can do this with Pretty Diff tool api: http://prettydiff.com/api.php
The actual application, prettydiff.js, is JavaScript, and the service processing the requests on the server is also JavaScript. To see this in action go to the test link and use the "Source URI" method of input.