Source code for /src/remote_view.js.txt
//======================================================================//
// Author: Mark Qian <markqian@hotmail.com> //
// WWW: http://www.coolshare.com //
// Copyright (c) 2006, Mark Qian //
// //
// You must contact Mark Qian to get a permission of use //
// in case you want to make any use of the codes except viewing it //
// on Mark's site. //
//======================================================================//
function view(s) {
var w = window.open("about:blank", "ViewWin", "left=20,top=20,width=630,height=550,toolbar=1,resizable=0");
w.document.open();
w.document.write("<html>");
w.document.write("<scr"+"ipt>");
w.document.write("function doOnload() {");
w.document.write(" var c = document.getElementById('a');");
w.document.write(" c.innerHTML = unescape(c.innerHTML);");
w.document.write("}");
w.document.write("</scr"+"ipt>");
w.document.write("<body onload=\"doOnload()\"><table><tr><td><textarea id=a style=\"width:600; height:500\">"+s+"</textarea></td></tr><tr><td align=center><input type=button value=\"OK\" onclick=\"window.close()\"></td></tr></table></body></html>");
w.document.close();
}
function remoteView(url) {
var viewRemote = new ViewRemote();
viewRemote.view(url);
}
function ViewRemote() {
this.view = function(url) {
this.getUrl(url, this.cb);
}
var self = this;
this.cb = function(status, headers, text) {
view(text);
}
this.getXmlHttp = function(){
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
////////////////// a closure is form to preserve self /////////////////
this.getUrl = function(url, cb) {
var xmlhttp = this.getXmlHttp();
xmlhttp.open("GET", url);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
self.cb(xmlhttp.status,
xmlhttp.getAllResponseHeaders(),
escape(xmlhttp.responseText));
}
}
xmlhttp.send(null);
}
}