<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jesal gadhia &#187; html</title>
	<atom:link href="http://jesal.us/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://jesal.us</link>
	<description></description>
	<lastBuildDate>Thu, 14 Jul 2011 18:51:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Cross-Domain Communication with IFrames</title>
		<link>http://jesal.us/2010/12/cross-domain-communication-with-iframes/</link>
		<comments>http://jesal.us/2010/12/cross-domain-communication-with-iframes/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 21:18:29 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://jesal.us/?p=259</guid>
		<description><![CDATA[Recently I encountered a situation where I had to communicate between an iframe located on a different domain and its parent. Due to the &#8220;same origin policy&#8221;, a security concept for browsers, which only permits scripts running on pages originating from the same site, this was not possible to do right out of the box. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I encountered a situation where I had to communicate between an iframe located on a different domain and its parent. Due to the &#8220;same origin policy&#8221;, a security concept for browsers, which only permits scripts running on pages originating from the same site, this was not possible to do right out of the box. After some Googling, I learned there were a couple of workarounds for it. You could use dynamic script tags included from external domains aka JSONP or use postMessage or the IFrame URL technique. All of these solutions are quite hackish or complicated and not 100% secure. Luckily I found this nice little library called <a href="http://easyxdm.net/">easyXDM</a>.</p>
<blockquote><p>At the core easyXDM provides a transport stack capable of passing string based messages between two windows, a consumer (the main document) and a provider (a document included using an iframe). It does this by using one of several available techniques, always selecting the most efficient one for the current browser. For all implementations the transport stack offers bi-directionality, reliability, queueing and sender-verification.</p></blockquote>
<p>Here&#8217;s a small test I created. It calls a function to scroll the page up from the remote site. Local and remote directories represent the servers where the files will be residing on.</p>
<p><strong>local/methods.html</strong></p>
<pre>
&lt;!doctype html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;easyXDM&lt;/title&gt;
        &lt;script type="text/javascript" src="easyXDM.js"&gt;
        &lt;/script&gt;
        &lt;script type="text/javascript"&gt;
            var REMOTE = (function(){
                var remote = location.href;
                switch (location.host) {
                    case "jesal.us":
                        location.href = remote.replace("provider", "consumer");
                        break;
                    case "calistolabs.com":
                        remote = remote.replace("calistolabs.com", "jesal.us");
                        break;
                }
                return remote.substring(0, remote.lastIndexOf("/"));
            }());
            var remote = new easyXDM.Rpc(/** The channel configuration */{
                /**
                 * Register the url to hash.html, this must be an absolute path
                 * or a path relative to the root.
                 * @field
                 */
                local: "name.html",
                /**
                 * Register the url to the remote interface
                 * @field
                 */
                remote: REMOTE + "/../remote/remotemethods.html",
                remoteHelper: REMOTE + "/../remote/name.html",
                /**
                 * Register the DOMElement that the generated IFrame should be inserted into
                 */
                container: "embedded",
                props: {
                    style: {
                        border: "2px dotted red",
                        height: "1200px"
                    }
                }
            }, /** The interface configuration */ {
                local: {
                    triggerScrollUp: function(){
						scroll(0,0);
                    }
                }
            });
        &lt;/script&gt;
        &lt;style type="text/css"&gt;
            #embedded iframe {
                width: 100%;
                height: 100%;
            }
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;script type="text/javascript"&gt;
            document.write("Domain: " + location.host);
        &lt;/script&gt;
            &lt;br/&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;br&gt;
			&lt;div id="embedded"&gt;
			&lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>remote/remotemethods.html</strong></p>
<pre>
&lt;!doctype html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;easyXDM&lt;/title&gt;
        &lt;script type="text/javascript" src="easyXDM.js"&gt;
        &lt;/script&gt;
        &lt;script type="text/javascript"&gt;
            var remote = new easyXDM.Rpc(/** The channel configuration*/{
                local: "name.html",
				onReady: function(){
                    /**
                     * Call a method on the other side
                     */
                    remote.triggerScrollUp();
                }
            }, /** The configuration */ {
                remote: {
                    triggerScrollUp: {}
                }
            });
        &lt;/script&gt;
    &lt;/head&gt;

    &lt;body&gt;
        &lt;script type="text/javascript"&gt;
            document.write("Domain: " + location.host);
        &lt;/script&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;br&gt;
		&lt;input type="button" onclick="remote.triggerScrollUp();" value="Call to triggerScrollUp on mother ship"/&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>remote/name.html</strong></p>
<pre>
&lt;!doctype html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;/title&gt;
        &lt;meta http-equiv="CACHE-CONTROL" content="PUBLIC"/&gt;
        &lt;meta http-equiv="EXPIRES" content="Sat, 01 Jan 2050 00:00:00 GMT"/&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;script type="text/javascript"&gt;

        function sendMessage(message, url){
            window.setTimeout(function(){
                window.name = message;
                location.href = url + "," + encodeURIComponent(location.protocol + "//" + location.host + location.pathname);
            }, 0);
        }

        if (location.hash) {
            if (location.hash.substring(1, 2) === "_") {
                var channel, url, hash = location.href.substring(location.href.indexOf("#") + 3), indexOf = hash.indexOf(",");
                if (indexOf == -1) {
                    channel = hash;
                }
                else {
                    channel = hash.substring(0, indexOf);
                    url = decodeURIComponent(hash.substring(indexOf + 1));
                }
                switch (location.hash.substring(2, 3)) {
                    case "2":
                        // NameTransport local
                        window.parent.parent.easyXDM.Fn.get(channel)(window.name);
                        location.href = url + "#_4" + channel + ",";
                        break;
                    case "3":
                        // NameTransport remote
                        var guest = window.parent.frames["easyXDM_" + channel + "_provider"];
                        if (!guest) {
                            throw new Error("unable to reference window");
                        }
                        guest.easyXDM.Fn.get(channel)(window.name);
                        location.href = url + "#_4" + channel + ",";
                        break;
                    case "4":
                        // NameTransport idle
                        var fn = window.parent.easyXDM.Fn.get(channel + "_load");
                        if (fn) {
                            fn();
                        }
                        break;
                }
            }
        }
        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>You can find lot more examples and documentation on easyXDM&#8217;s <a href="http://easyxdm.net/wp/category/examples/">website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2010/12/cross-domain-communication-with-iframes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to easily parse HTML without RegEx</title>
		<link>http://jesal.us/2008/05/how-to-easily-parse-html-without-regex/</link>
		<comments>http://jesal.us/2008/05/how-to-easily-parse-html-without-regex/#comments</comments>
		<pubDate>Tue, 06 May 2008 16:50:04 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=91</guid>
		<description><![CDATA[I recently discovered an absolutely amazing HTML parsing library for .NET called HtmlAgilityPack. It completely takes away the pain of parsing complicated HTML with regular expressions. Here&#8217;s a very simple example of what you could do with it &#8211; I&#8217;m just extracting inner HTML from any element inside a HTML file which has a css [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered an absolutely amazing HTML parsing library for .NET called <a href="http://www.codeplex.com/htmlagilitypack" target="_blank">HtmlAgilityPack</a>. It completely takes away the pain of parsing complicated HTML with regular expressions.</p>
<p>Here&#8217;s a very simple example of what you could do with it &#8211; I&#8217;m just extracting inner HTML from any element inside a HTML file which has a css class called &#8220;scrape&#8221; assigned to it:<br />
<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">using</span> HtmlAgilityPack;

<span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> _Default : System.Web.UI.Page
{
    <span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e)
    {
        HtmlDocument doc = <span class="kwrd">new</span> HtmlDocument();
        doc.Load(Server.MapPath(filePath));
        Parse(doc.DocumentNode);
    }
    <span class="kwrd">private</span> <span class="kwrd">void</span> Parse(HtmlNode n)
    {
        <span class="kwrd">foreach</span> (HtmlAttribute atr <span class="kwrd">in</span> n.Attributes)
        {
            <span class="kwrd">if</span> (atr.Name == <span class="str">"class"</span> &amp;&amp; atr.Value == <span class="str">"scrape"</span>)
            {
                Response.Write(n.InnerHtml);
            }
        }

        <span class="kwrd">if</span> (n.HasChildNodes)
        {
            <span class="kwrd">foreach</span> (HtmlNode cn <span class="kwrd">in</span> n.ChildNodes)
            {
                Parse(cn);
            }
        }
    }
}
</pre>
<p>
That&#8217;s just a very small part of what it could do. I&#8217;ll expand upon this and post a few more examples in the future showing some interesting things you could do with this. </p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/05/how-to-easily-parse-html-without-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to extract URLs (href property) from HTML</title>
		<link>http://jesal.us/2008/01/how-to-extract-urls-href-property-from-html/</link>
		<comments>http://jesal.us/2008/01/how-to-extract-urls-href-property-from-html/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 07:13:09 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/2008/01/05/how-to-extract-urls-href-property-from-html/</guid>
		<description><![CDATA[protected ArrayList getURL(string txtIn) { ArrayList outURL = new ArrayList(); Regex r = new Regex("href\\s*=\\s*(?:(?:\\\"(?&#60;url&#62;[^\\\"]*)\\\")&#124;(?&#60;url&#62;[^\\s]* ))"); MatchCollection mc1 = r.Matches(txtIn); foreach (Match m1 in mc1) { foreach (Group g in m1.Groups) { outURL.Add(g.Value); } } return outURL; }]]></description>
			<content:encoded><![CDATA[<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode" style="overflow-y:hidden">
<span class="kwrd">protected</span> ArrayList getURL(<span class="kwrd">string</span> txtIn)
{
    ArrayList outURL = <span class="kwrd">new</span> ArrayList();
    Regex r = <span class="kwrd">new</span> Regex(<span class="str">"href\\s*=\\s*(?:(?:\\\"(?&lt;url&gt;[^\\\"]*)\\\")|(?&lt;url&gt;[^\\s]* ))"</span>);
    MatchCollection mc1 = r.Matches(txtIn);

    <span class="kwrd">foreach</span> (Match m1 <span class="kwrd">in</span> mc1)
    {
        <span class="kwrd">foreach</span> (Group g <span class="kwrd">in</span> m1.Groups)
        {
            outURL.Add(g.Value);
        }
    }

    <span class="kwrd">return</span> outURL;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/01/how-to-extract-urls-href-property-from-html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Strip out HTML tags using RegEx</title>
		<link>http://jesal.us/2007/11/strip-out-html-tags-via-regex/</link>
		<comments>http://jesal.us/2007/11/strip-out-html-tags-via-regex/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 04:16:51 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/2007/11/13/strip-out-html-tags-via-regex/</guid>
		<description><![CDATA[This code will strip out all the HTML tags and truncate the text to 4 lines. public static string TruncateText(string txtIn, int newLength) { string txtOut = txtIn; string pattern = @"&#60;(.&#124;\n)*?&#62;"; //Strip out HTML tags if (Regex.IsMatch(txtIn, pattern, RegexOptions.None)) txtOut = Regex.Replace(txtIn, pattern, string.Empty, RegexOptions.Multiline).Trim(); if (txtOut.Length &#62; newLength) { int endPos = txtOut.LastIndexOf(" [...]]]></description>
			<content:encoded><![CDATA[<p>This code will strip out all the HTML tags and truncate the text to 4 lines.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> TruncateText(<span class="kwrd">string</span> txtIn, <span class="kwrd">int</span> newLength)
{
    <span class="kwrd">string</span> txtOut = txtIn;
    <span class="kwrd">string</span> pattern = <span class="str">@"&lt;(.|\n)*?&gt;"</span>;

    <span class="rem">//Strip out HTML tags</span>
    <span class="kwrd">if</span> (Regex.IsMatch(txtIn, pattern, RegexOptions.None))
        txtOut = Regex.Replace(txtIn, pattern, <span class="kwrd">string</span>.Empty, RegexOptions.Multiline).Trim();

    <span class="kwrd">if</span> (txtOut.Length &gt; newLength)
    {
        <span class="kwrd">int</span> endPos = txtOut.LastIndexOf(<span class="str">" "</span>, newLength);
        txtOut = txtOut.Substring(0, endPos) + <span class="str">"..."</span>;
    }

    <span class="kwrd">return</span> txtOut;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2007/11/strip-out-html-tags-via-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

