/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Get the contents returned from a web URL. * @param {string} urlStr The web address of the page you wish to fetch. * @returns {string} The contents of the web page. */ function fetch(urlStr) { if (typeof java == "undefined") { throw "This script requires java to run."; } else { importPackage(java.io, java.net); var url = new URL(urlStr); var urlStream = url.openStream(); var reader = new BufferedReader(new InputStreamReader(urlStream, "latin1")); var html = ""; var line; while (line = reader.readLine()) { if (line == null) break; html += line; } return html; } }