That would work, and would probably be less CPU and bandwidth intensive. I was concerned about special characters initially, and wanted to make a proof of concept. Does what I'm doing make any sense to do though? Am I correct in that a read-only version of the DOM is unavailable otherwise?
On Feb 9, 4:29 pm, Ricardo Tomasi <ricardob...@gmail.com> wrote: > Why not simply use escaped plain text? > > On Feb 9, 6:04 pm, jay <jay.ab...@gmail.com> wrote: > > > I'm playing around with writing a server-side script that generates > > JSONP from content that is downloaded by the script (URL is passed to > > script from querystring). Is there a better way to do it than to > > encode it as base64, or is there a work-around that doesn't require > > any server-side code? I'm basically trying to get access to a given > > page's DOM cross-domain using minimal server-side code. I suppose one > > thing that would be needed here is a regex to replace non http src > > attributes. > > > Here is what I have so far: > > //test.htm > > <body> > > <div id="mydiv"></div> > > <script src="jquery.js"></script> > > <script src="jquery.base64.js"></script> > > <script> > > function callback(e){ > > alert(e.data); > > alert($.base64Decode(e.data)); > > $("#mydiv").html($.base64Decode(e.data));} > > > </script> > > <script src="test.aspx?url=www.wikipedia.org"></script> > > </body> > > > //test.aspx > > <%@ Page Language="C#" AutoEventWireup="true" %> > > <%@ Import Namespace="System" %> > > <%@ Import Namespace="System.IO" %> > > <%@ Import Namespace="System.Net" %> > > <%@ Import Namespace="System.Text" %> > > <script runat="server"> > > void Page_Load( object sender, EventArgs e ){ > > string url = Request["url"] ?? ""; > > Response.Write("callback({data:\""+EncodeTo64(Get(url))+"\"})"); > > Response.End();} > > > string EncodeTo64(string toEncode){ > > byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes > > (toEncode); > > string returnValue = System.Convert.ToBase64String > > (toEncodeAsBytes); > > return returnValue;} > > > string Get(string strURL){ > > WebRequest myWebRequest = WebRequest.Create("http://"+strURL); > > WebResponse myWebResponse = myWebRequest.GetResponse(); > > Stream ReceiveStream = myWebResponse.GetResponseStream(); > > Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); > > StreamReader readStream = new StreamReader( ReceiveStream, > > encode ); > > return readStream.ReadToEnd();} > > > </script>