<?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>@InitBinder &#187; javascript</title>
	<atom:link href="http://initbinder.com/categories/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://initbinder.com</link>
	<description>My thoughts, notes and ideas as a passionate software engineer</description>
	<lastBuildDate>Sat, 24 Mar 2012 13:29:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Jquery UI: Add a Shadow Line Around a Dialog Box</title>
		<link>http://initbinder.com/articles/jquery-ui-add-a-shadow-around-a-dialog-box.html</link>
		<comments>http://initbinder.com/articles/jquery-ui-add-a-shadow-around-a-dialog-box.html#comments</comments>
		<pubDate>Sat, 23 Apr 2011 13:13:39 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[css dialog]]></category>
		<category><![CDATA[css modal dialog]]></category>
		<category><![CDATA[css popup]]></category>
		<category><![CDATA[css popup box]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://javabeans.asia/?p=1000</guid>
		<description><![CDATA[I really like the style of Facebook (or LinkedIn) Javascript popup dialogs &#8211; a thin semi-transparent shadow line around the dialog. It looks nice and from the usability point of view it has a purpose, as it is attracts user&#8217;s &#8230; <a href="http://initbinder.com/articles/jquery-ui-add-a-shadow-around-a-dialog-box.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I really like the style of <a title="Facebook" href="http://facebook.com/" target="_blank">Facebook</a> (or <a title="LinkedIn" href="http://linkedin.com/" target="_blank">LinkedIn</a>) Javascript popup dialogs &#8211; a thin semi-transparent shadow line around the dialog. It looks nice and from the usability point of view it has a purpose, as it is attracts user&#8217;s attention to the important component on the screen.</p>
<p>There are many examples of custom Javascript dialogs on the Internet that explain how to achieve this. While many solutions are really good, I wanted to make use of the dialog provided by jQuery UI library by default.</p>
<p>I have came up with a solution that works, but I don&#8217;t think it is the most elegant way to do it (CSS is not my strong side). The solution is quite simple, and pretty straight forward (I think <img src='http://initbinder.com/bunker/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). The following are the final results as tested in FF3, IE8, Opera 10 and Chrome 10, please note the shadow line around the dialog:</p>
<div id="attachment_1010" class="wp-caption aligncenter" style="width: 310px"><a href="http://initbinder.com/bunker/wp-content/uploads/2011/04/ff-3.6.16.png"><img class="size-medium wp-image-1010  " title="Firefox - jQuery dialog box with semi-transparent shadow around it" src="http://initbinder.com/bunker/wp-content/uploads/2011/04/ff-3.6.16-300x116.png" alt="Firefox - jQuery dialog box with semi-transparent shadow around it" width="300" height="116" /></a><p class="wp-caption-text">Firefox 3.6.16</p></div>
<div id="attachment_1011" class="wp-caption aligncenter" style="width: 310px"><a href="http://initbinder.com/bunker/wp-content/uploads/2011/04/ie-8.0.76.png"><img class="size-medium wp-image-1011  " title="Internet Explorer - jQuery dialog box with semi-transparent shadow around it" src="http://initbinder.com/bunker/wp-content/uploads/2011/04/ie-8.0.76-300x136.png" alt="Internet Explorer - jQuery dialog box with semi-transparent shadow around it" width="300" height="136" /></a><p class="wp-caption-text">Internet Explorer 8.0.76</p></div>
<div id="attachment_1047" class="wp-caption aligncenter" style="width: 310px"><a href="http://initbinder.com/bunker/wp-content/uploads/2011/04/opera-10.63.jpg"><img class="size-medium wp-image-1047" title="opera-10.63" src="http://initbinder.com/bunker/wp-content/uploads/2011/04/opera-10.63-300x124.jpg" alt="opera-10.63" width="300" height="124" /></a><p class="wp-caption-text">opera-10.63</p></div>
<p><a href="http://initbinder.com/bunker/wp-content/uploads/2011/04/chrome-10.0.648.jpg"><img class="aligncenter size-medium wp-image-1048" title="chrome-10.0.648" src="http://initbinder.com/bunker/wp-content/uploads/2011/04/chrome-10.0.648-300x126.jpg" alt="chrome-10.0.648" width="300" height="126" /></a></p>
<p>First I defined a CSS class that&#8217;s going to have properties for the background shadow (the <em>bg_dialog_modeless_mask.png</em> is an 8&#215;8 gray square image)</p>
<p>[css]<br />
.dialog-mask {<br />
 -moz-border-radius:5px 5px 5px 5px;<br />
 -webkit-border-radius: 5px;<br />
 border-radius: 5px;<br />
 background:url(&quot;../images/bg_dialog_modeless_mask.png&quot;) repeat scroll left top transparent;<br />
}<br />
[/css]</p>
<p>Somewhere on my HTML page, I defined a DIV that&#8217;s going to be the dialog holder:</p>
<p>[html]<br />
&lt;div id=&quot;popup-holder&quot;&gt;&lt;/div&gt;<br />
[/html]</p>
<p>I added jQuery dialog init statement in my global JS file:</p>
<p>[javascript]<br />
$(document).ready(function(){</p>
<p> $( &#8216;#popup-holder&#8217; ).dialog({<br />
       autoOpen: false,<br />
       height: 350,<br />
       width: 530,<br />
       modal: true,<br />
       resizable: true,<br />
       draggable: false,<br />
       buttons: {<br />
         Cancel: function() {<br />
            $( this ).dialog( &quot;close&quot; );<br />
            $( &#8216;#dialog-wrapper&#8217; ).remove();<br />
         }<br />
      },<br />
      close: function() {<br />
            $( &#8216;#dialog-wrapper&#8217; ).remove();<br />
      },<br />
      open: function() {<br />
            wrapJqueryDialog($( this ));<br />
      },<br />
      resize: function() {<br />
            wrapJqueryDialog($( this ));<br />
      }<br />
   });<br />
});<br />
[/javascript]</p>
<p>The <em>#dialog-wrapper</em> is the ID of the DIV that holds the semi-transparent shadow which wraps the dialog. The <em>wrapJqueryDialog</em> function creates the shadow when dialog is opened, and handles the shadow resize when dialog is resized (it is also possible to add an event to drag the shadow when dialog has <em>draggable </em>option set to true).</p>
<p>Now the important part, the <em>wrapJqueryDialog</em> function:</p>
<p>[javascript]<br />
function wrapJqueryDialog(dialogWidgetObj)  {<br />
	//The width and height of the shadow line wrapping the dialog<br />
        var shadowWidth = 20;</p>
<p>        //Lets remove the shadow holder to start clean<br />
	$( &#8216;#dialog-wrapper&#8217; ).remove();</p>
<p>        //Gets the current dialog widget<br />
	var widget = dialogWidgetObj.dialog( &quot;widget&quot; );</p>
<p>        //Create the shadow holder DIV that has the background shadow CSS class<br />
	var dialogwrapper = $(&#8216;&lt;div id=&quot;dialog-wrapper&quot; class=&quot;dialog-mask&quot; /&gt;&#8217;);</p>
<p>	//For IE, the holder must be appended to the body first before any manipulation.<br />
	$(&#8216;body&#8217;).append(dialogwrapper);</p>
<p>        //Lets copy default inline styles from the dialog widget to the shadow holder<br />
	dialogwrapper.attr(&quot;style&quot;, widget.attr(&quot;style&quot;));</p>
<p>        //Lets position the shadow holder before and above the dialog widget<br />
	dialogwrapper.css(&quot;top&quot;, parseInt(dialogwrapper.css(&quot;top&quot;)) &#8211; shadowWidth);<br />
	dialogwrapper.css(&quot;left&quot;, parseInt(dialogwrapper.css(&quot;left&quot;)) &#8211; shadowWidth);</p>
<p>        dialogwrapper.css(&quot;position&quot;, &quot;absolute&quot;);</p>
<p>	//Make sure that the dialog widget is infront of surrounding shadow box and overlay (if there is one set)<br />
	widget.css(&quot;z-index&quot;, (parseInt(widget.css(&quot;z-index&quot;)) + 1));</p>
<p>	//Add to the shadow width default padding value from the class &#8216;.ui-dialog&#8217; and<br />
	//default border width from the class &#8216;.ui-widget-content&#8217; (1px times two)<br />
	var finalShadowWidth = shadowWidth + parseInt(widget.css(&quot;padding-top&quot;)) + 2;</p>
<p>	var widgetHeight = parseInt(widget.css(&quot;height&quot;));<br />
        //Lets extend the shadow holder height<br />
	dialogwrapper.css(&quot;height&quot;, widgetHeight + (finalShadowWidth * 2));</p>
<p>	var widgetWidth = parseInt(widget.css(&quot;width&quot;));<br />
	//Lets extend the shadow holder width<br />
        dialogwrapper.css(&quot;width&quot;, widgetWidth + (finalShadowWidth * 2));<br />
}<br />
[/javascript]</p>
<p>That&#8217;s all when it comes to code (don&#8217;t forget to add to your HTML/JS code a dialog trigger, it can be a link or a button). I am really interested to hear your comments about it and suggestions. If you can suggest a better way of implementation &#8211; please do so, I am really keen to know <img src='http://initbinder.com/bunker/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/jquery-ui-add-a-shadow-around-a-dialog-box.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How To Select a Child Element Using jQuery</title>
		<link>http://initbinder.com/articles/how-to-select-sub-element-html.html</link>
		<comments>http://initbinder.com/articles/how-to-select-sub-element-html.html#comments</comments>
		<pubDate>Wed, 17 Nov 2010 01:19:24 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://javabeans.asia/?p=849</guid>
		<description><![CDATA[Let’s assume you have an HTML string containing a parent element with a number of children and their sub children elements. If you’d like to extract HTML of one of the children (by class name or id), you can use &#8230; <a href="http://initbinder.com/articles/how-to-select-sub-element-html.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Let’s assume you have an HTML string containing a parent element with a number of children and their sub children elements. If you’d like to extract HTML of one of the children (by class name or id), you can use this jQuery line:</p>
<p>[javascript]<br />
var html = $(htmlString).find(&#8216;div.target&#8217;).html();<br />
[/javascript]</p>
<p>It can be useful when you get an AJAX response from the server, and only a particular section needs to extracted.</p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/how-to-select-sub-element-html.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX Call Fails in Firefox</title>
		<link>http://initbinder.com/articles/ajax-call-fails-in-firefox.html</link>
		<comments>http://initbinder.com/articles/ajax-call-fails-in-firefox.html#comments</comments>
		<pubDate>Sun, 31 Oct 2010 01:39:15 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[html snippet]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://javabeans.asia/?p=831</guid>
		<description><![CDATA[Apparently AJAX request fails in Firefox 3 (400 Bad request) when an HTML button that makes the request using an onClick() event, enclosed within a form tag. The button is not a &#8220;submit&#8221; button of the form. Having said that, &#8230; <a href="http://initbinder.com/articles/ajax-call-fails-in-firefox.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Apparently AJAX request fails in Firefox 3 (400 Bad request) when an HTML button that makes the request using an onClick() event, enclosed within a form tag. The button is not a &#8220;submit&#8221; button of the form.</p>
<p>Having said that, the whole thing works fine in IE6 and Chrome.</p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/ajax-call-fails-in-firefox.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Enriching Rich Internet Applications with Rule-Based Reasoning</title>
		<link>http://initbinder.com/articles/enriching_rich_internet_applications_with_rule_based_reasoning.html</link>
		<comments>http://initbinder.com/articles/enriching_rich_internet_applications_with_rule_based_reasoning.html#comments</comments>
		<pubDate>Mon, 22 Feb 2010 14:00:00 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[drools]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[firefox add-on]]></category>
		<category><![CDATA[json rules]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[web rules]]></category>

		<guid isPermaLink="false">http://javabeans.asia/2010/02/23/enriching_rich_internet_applications_with_rule_based_reasoning.html</guid>
		<description><![CDATA[I came across a Firefox Add-On today by Matthias Tylkowski, that lets user to modify the browser view of his/her preferred web pages. For example, user can modify the appearance of cnn.com to suit his/her needs. The add-on or the &#8230; <a href="http://initbinder.com/articles/enriching_rich_internet_applications_with_rule_based_reasoning.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I came across a Firefox <span class="removed_link" title="https://addons.mozilla.org/en-US/firefox/addon/8098/">Add-On</span> today by Matthias Tylkowski, that lets user to modify the browser view of his/her  preferred web pages. For example, user can modify the appearance of <a title="CNN News" href="http://www.cnn.com" target="_blank">cnn.com</a> to suit his/her needs.</p>
<p>The add-on or the web rules is a JSON-based rule language, where each rule is a JSON object. In addition, Javascript is used for method calls. The web rules use Drools-like condition language:</p>
<p>[java]<br />
{<br />
    &amp;quot;id&amp;quot;:&amp;quot;rule101&amp;quot;,  &amp;quot;appliesTo&amp;quot;: [<br />
              &amp;quot;http://www.cnn.com&amp;quot;],<br />
               &amp;quot;condition&amp;quot;:  &amp;quot;$X:Element( class == &#8216;note&#8217;, $Y:firstChild ) &amp;amp;&amp;amp;<br />
                              ($Y.nodeName == &#8216;ul&#8217;)&amp;quot;,<br />
               &amp;quot;actions&amp;quot;:[  &amp;quot;changeBackground($Y, 'blue')&amp;quot;   ]<br />
}<br />
[/java]</p>
<p>For all elements of class <strong><em>note</em></strong> having as first child an <strong><em>ul</em></strong>, change the first child background color to blue.<strong> </strong></p>
<p>I think its a quite cool add-on.</p>
<p>Resources:<br />
<em><a href="http://bpt.hpi.uni-potsdam.de/pub/Public/EmilianPascalau/JSONRulesSlides.pdf" target="_blank">JSON RuleS</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/enriching_rich_internet_applications_with_rule_based_reasoning.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Redefining Web Applications with AJAX, Servlets and JSON</title>
		<link>http://initbinder.com/articles/redefining_web_applications_with_ajax_servlets_and_json.html</link>
		<comments>http://initbinder.com/articles/redefining_web_applications_with_ajax_servlets_and_json.html#comments</comments>
		<pubDate>Sun, 13 Sep 2009 04:00:00 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[servlets]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[atom parser]]></category>
		<category><![CDATA[rss parser]]></category>

		<guid isPermaLink="false">http://javabeans.asia/2009/09/13/redefining_web_applications_with_ajax_servlets_and_json.html</guid>
		<description><![CDATA[In this article I would like to show how JSON (JavaScript Object Notation) and Java servlet can be used together in a little AJAX (Asynchronous JavaScript and XML) application. To give brief description to those who are not closely familiar &#8230; <a href="http://initbinder.com/articles/redefining_web_applications_with_ajax_servlets_and_json.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this article I would like to show how JSON (JavaScript Object Notation) and Java servlet can be used together in a little AJAX (Asynchronous JavaScript and XML) application.</p>
<p>To give brief description to those who are not closely familiar with JSON -</p>
<p>JSON is a lightweight syntax for representing data, which makes working with it much more pleasant than with XML and makes AJAX applications faster. Also, when working with JSON, there is no need for an XML parsing.</p>
<p>In the following example, I am going to create a callback servlet that fetches and parses an RSS feed. Then the parsed feed data is passed to the client side in a form of JSON. The data then formatted and presented to the user. The client uses AJAX call to query the servlet.</p>
<p>For this application, I used three third-party libraries:</p>
<ol>
<li><strong>JSON library</strong> provided by <a title="JSON" onclick="javascript:pageTracker._trackPageview('/outbound/article/json.org');" rel="nofollow" href="http://json.org/java/" target="_new">JSON.org</a> and extended by <span class="removed_link" title="http://oss.metaparadigm.com/jsonrpc/index.html">JSON-RPC-Java</span> which allows to create and easily parse JSON data through Java code. This library can run in a Servlet container such as Tomcat, JBoss and other J2EE Application servers.</li>
<li><a title="Project ROME" href="https://rome.dev.java.net/" target="_blank">Project ROME</a><br />
ROME is an set of open source Java tools for parsing, generating and publishing RSS and Atom feeds.</li>
<li><a title="JDOM XML parser" href="http://jdom.org" target="_blank">JDOM XML parser</a><br />
JDOM is a Java-based &#8220;document object model&#8221; for XML files. JDOM serves the same purpose as DOM, but is easier to use</li>
</ol>
<p>The libraries are included in the source code which accompanies this article. This application example is also included as a WAR archive, ready to be deployed on Tomcat.</p>
<p>The following is my servlet implementation. The servlet fetches and parses feed data. The JSON library mentioned previously allows me easily to create and populate JSON object.</p>
<p>[java]<br />
import javax.servlet.http.HttpServletRequest;<br />
import javax.servlet.http.HttpServletResponse;<br />
import org.json.JSONArray;<br />
import org.json.JSONObject;</p>
<p>import com.sun.syndication.feed.synd.SyndEntry;<br />
import com.sun.syndication.feed.synd.SyndFeed;<br />
import com.sun.syndication.fetcher.FeedFetcher;<br />
import com.sun.syndication.fetcher.FetcherException;<br />
import com.sun.syndication.fetcher.impl.FeedFetcherCache;<br />
import com.sun.syndication.fetcher.impl.HashMapFeedInfoCache;<br />
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;<br />
import com.sun.syndication.io.FeedException;</p>
<p>/**<br />
* @author Alexander Zagniotov (http://javabeans.asia)<br />
*/<br />
public class JsonServlet extends HttpServlet {</p>
<p>	private static final long serialVersionUID = 1L;<br />
	private static final String BLOG_URL = &amp;quot;http://javabeans.asia/rss.xml&amp;quot;;<br />
	private static final String CONTENT_TYPE = &amp;quot;application/json&amp;quot;;<br />
	private FeedFetcherCache feedInfoCache = null;<br />
	private FeedFetcher feedFetcher = null;</p>
<p>	public void init(ServletConfig config) throws ServletException {<br />
		super.init(config);<br />
		feedInfoCache = HashMapFeedInfoCache.getInstance();<br />
		feedFetcher = new HttpURLFeedFetcher(feedInfoCache);<br />
	}</p>
<p>	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {</p>
<p>		SyndFeed feed = this.feedFethcer(BLOG_URL);<br />
		if (feed != null) {<br />
			String json = this.feedToJSON(feed);<br />
			response.setContentType(CONTENT_TYPE);<br />
			response.setHeader(&amp;quot;Cache-Control&amp;quot;, &amp;quot;no-cache&amp;quot;);<br />
			response.getWriter().write(json);<br />
		}<br />
	}</p>
<p>	private SyndFeed feedFethcer(String url) {<br />
		SyndFeed feed = null;<br />
		try {<br />
			feed = feedFetcher.retrieveFeed(new URL(BLOG_URL));<br />
		} catch (IllegalArgumentException e) {<br />
			e.printStackTrace();<br />
		} catch (FeedException e) {<br />
			e.printStackTrace();<br />
		} catch (FetcherException e) {<br />
			e.printStackTrace();<br />
		} catch (MalformedURLException e) {<br />
			e.printStackTrace();<br />
		} catch (IOException e) {<br />
			e.printStackTrace();<br />
		}<br />
		return feed;<br />
	}</p>
<p>	private String feedToJSON(SyndFeed feed) {</p>
<p>		JSONObject jsonObj = new JSONObject();<br />
		JSONArray jsonEntryTitles = new JSONArray();<br />
		jsonObj.put(&amp;quot;blogtitle&amp;quot;, feed.getTitle());<br />
		jsonObj.put(&amp;quot;blogdescription&amp;quot;, feed.getDescription());<br />
		jsonObj.put(&amp;quot;bloglanguage&amp;quot;, feed.getLanguage());<br />
		jsonObj.put(&amp;quot;bloglink&amp;quot;, feed.getLink());<br />
		jsonObj.put(&amp;quot;author&amp;quot;, feed.getCopyright());</p>
<p>		List&amp;lt;?&amp;gt; feedEntries = feed.getEntries();</p>
<p>		for (Object c : feedEntries) {<br />
			SyndEntry syndicateEntry = (SyndEntry) c;<br />
			jsonEntryTitles.put(syndicateEntry.getTitle());<br />
		}</p>
<p>		jsonObj.put(&amp;quot;blogentrytitles&amp;quot;, jsonEntryTitles);<br />
		return jsonObj.toString();<br />
	}<br />
}<br />
[/java]</p>
<p>As you can see it is very easy to construct JSON objects and arrays on the server side and pass them to the client. For the purpose of this example I am getting my data from RSS feed, but the data can also be coming from DB etc.</p>
<p>The following is my client implementation. The client queries the servlet using AJAX call. When an AJAX call returns a response from the servlet in a form of JSON object, the object data is formatted and information about the RSS feed is presented to the client:</p>
<p>[java]<br />
&amp;lt;html&amp;gt;<br />
    &amp;lt;head&amp;gt;<br />
    &amp;lt;title&amp;gt;Java Beans dot Asia&amp;lt;/title&amp;gt;</p>
<p>    &amp;lt;script language=&amp;quot;JavaScript&amp;quot; type=&amp;quot;text/javascript&amp;quot;&amp;gt;</p>
<p>        var httpRequest = null;</p>
<p>    function getDescriptionAsJSON() {<br />
        var description = document.getElementById(&#8216;description&#8217;);<br />
        description.innerHTML = &amp;quot;Loading, please wait &#8230;&amp;quot;;</p>
<p>        var url = &amp;quot;http://localhost:8080/json/json&amp;quot;;<br />
        if(window.XMLHttpRequest){<br />
            httpRequest = new XMLHttpRequest();<br />
        } else if(window.ActiveXObject){<br />
            httpRequest = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);<br />
        }</p>
<p>        httpRequest.open(&amp;quot;GET&amp;quot;, url, true);<br />
        httpRequest.onreadystatechange = handler;<br />
        httpRequest.send(null);<br />
    }</p>
<p>    function handler() {<br />
        if (httpRequest.readyState == 4) {<br />
            if (httpRequest.status == 200) {<br />
                processJSON(httpRequest.responseText);<br />
            }<br />
        }<br />
    }</p>
<p>    function processJSON(jsonObjectString) {</p>
<p>        var description = document.getElementById(&#8216;description&#8217;);</p>
<p>        //Since JSON is a subset of JavaScript, I am using<br />
        //JavaScript&#8217;s own compiler to parse JSON in one line!</p>
<p>        var jsonObject = eval(&#8216;(&#8216; + jsonObjectString + &#8216;)&#8217;)<br />
        var text = &amp;quot;&amp;quot;;</p>
<p>        text += &amp;quot;Author: &amp;quot; + jsonObject.author + &amp;quot;&amp;lt; br /&amp;gt;&amp;quot;;<br />
        text += &amp;quot;Blog Name: &amp;quot; + jsonObject.blogtitle + &amp;quot;&amp;lt; br /&amp;gt;&amp;quot;;<br />
        text += &amp;quot;Blog URL: &amp;quot; +    jsonObject.bloglink + &amp;quot;&amp;lt; br /&amp;gt;&amp;quot;;<br />
        text += &amp;quot;Blog Description: &amp;quot; +    jsonObject.blogdescription + &amp;quot;&amp;lt; br /&amp;gt;&amp;quot;;<br />
        text += &amp;quot;Blog Language: &amp;quot; + jsonObject.bloglanguage + &amp;quot;&amp;lt; br /&amp;gt;&amp;quot;;</p>
<p>        description.innerHTML = text;<br />
        var entries = &amp;quot;Last &amp;quot; + jsonObject.blogentrytitles.length + &amp;quot; blog entries are:nn&amp;quot;;</p>
<p>        for (var index = 0; index &amp;lt; jsonObject.blogentrytitles.length; index ++) {<br />
            entries += (index + 1) + &amp;quot;: &amp;quot; + jsonObject.blogentrytitles[index] + &amp;quot;n&amp;quot;;<br />
        }<br />
        alert(entries);<br />
    }</p>
<p>    &amp;lt;/script&amp;gt;</p>
<p>    &amp;lt;/head&amp;gt;<br />
    &amp;lt;body&amp;gt;<br />
        &amp;lt;img src=&amp;quot;images/javabeansmugshot_120x120.jpg&amp;quot; border=&amp;quot;1&amp;quot; /&amp;gt;&amp;lt; br /&amp;gt;&amp;lt; br /&amp;gt;<br />
        &amp;lt;div id=&amp;quot;description&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&amp;lt; br /&amp;gt;&amp;lt; br /&amp;gt;<br />
        &amp;lt;a href=&amp;quot;javascript:void(0)&amp;quot; onclick=&amp;quot;return getDescriptionAsJSON();&amp;quot;&amp;gt;Click to get description!&amp;lt;/a&amp;gt;<br />
    &amp;lt;/body&amp;gt;<br />
&amp;lt;/html&amp;gt;<br />
[/java]</p>
<p>As you could see, JSON data can be easily parsed on the client side with the help of Java script <em>eval()</em> function. To remind &#8211; JSON is a subset of Java script, therefore<em> eval()</em> will produce a valid object.</p>
<p>Keep in mind, that there is a need for extra care when using <em>eval</em>. The problem is that <em>eval</em> will compile and execute Java script code that coming back from the response. This could cause a security risk if the response data is coming from an untrusted source.</p>
<p>That&#8217;s it. I hope this example was clear and helpful <img src='http://initbinder.com/bunker/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://initbinder.com/bunker/wp-content/uploads/2010/06/json_servlets_ajax_war.zip">source json servlets ajax</a></p>
<p>Please note that this example was tested by me and its working fine. The source code as mentioned previously is included  as Eclipse project. You can simply create a new Java project from the existing Ant build.xml file.</p>
<p>Comments/flames are appreciated <img src='http://initbinder.com/bunker/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/redefining_web_applications_with_ajax_servlets_and_json.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Prevent iFrame Breakaway</title>
		<link>http://initbinder.com/articles/how_to_prevent_iframe_breakaway.html</link>
		<comments>http://initbinder.com/articles/how_to_prevent_iframe_breakaway.html#comments</comments>
		<pubDate>Sun, 29 Mar 2009 06:37:00 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[design patterns]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[iframe breakaway]]></category>
		<category><![CDATA[iframe breakout]]></category>

		<guid isPermaLink="false">http://javabeans.asia/2009/03/29/how_to_prevent_iframe_breakaway.html</guid>
		<description><![CDATA[Few days ago I was searching for a solution to the problem I&#8217;ve encountered &#8211; I needed to prevent a third party page to break out of iframe inside a web page of my web application. For people who are &#8230; <a href="http://initbinder.com/articles/how_to_prevent_iframe_breakaway.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Few days ago I was searching for a solution to the problem I&#8217;ve encountered &#8211; I needed to prevent a third party page to break out of iframe inside a web page of my web application. For people who are not closely familiar with JavaScript, the following JS snippet will make it more clear how page can break out of iframe:</p>
<p>[java]<br />
if (top.location.href != self.location.href)  {<br />
    top.location.href = self.location.href;<br />
}<br />
[/java]</p>
<p>If the current page is not the parent window &#8211; become the parent window.</p>
<p>I needed to implement something on my end, that would block or prevent the above script or similar to it from executing. I&#8217;ve spent several hours browsing the Net, talking to people on IRC and simply playing trial and error.</p>
<p>After some time, I understood that I wont be able to find a solution to my problem, simply because there is none unfortunately. But, having said that, I have some findings to share:</p>
<ol>
<li>There is iframe <em>security </em>attribute which only works on IE. Setting this attribute to security=&#8221;restricted&#8221;, will prevent iframe to break out. Its always &#8220;nice&#8221; to see that MS have few tricks up their sleeve <img src='http://initbinder.com/bunker/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Also, on one of the forums, someone mentioned that the same attribute will work under Opera as well as under IE. I personally haven&#8217;t tested it my self under Opera, I can just say that it works for IE and not FF.</li>
<li>To make use of <em>window.onbeforeunload</em> event and prompt user with a dialog that requires user&#8217;s input if he agrees to navigate away from the current page. If user disagrees (clicks &#8220;cancel&#8221;), he will remain on the current page. So here in a sense iframe breakaway was canceled. By the way, there is no way to suppress the dialog prompt and make event from clicking &#8220;cancel&#8221; default.</li>
<li>To grab the content of third party page using <a title="http://au.php.net/curl" href="http://au.php.net/curl" target="_blank">PHP Curl</a> lib and to create your own placeholder page for that content. Then the placeholder page can be put inside iframe. The page or the grabbed content will not attempt to breakout, but any request submitted to the placeholder page (hyper link or button click on the grabbed content) will cause page to unload.</li>
</ol>
<p>Also, while researching, I came across this <a title="Preventing Frame Busting and Click Jacking (UI Redressing)" href="http://coderrr.wordpress.com/2009/02/13/preventing-frame-busting-and-click-jacking-ui-redressing/" target="_blank">post</a> that talks about preventing iframe breakaway and click jacking with the help of 204 header response code.</p>
<p>After all that, my conclusion is:<br />
If the page inside iframe is not yours, in other words it is a page hosted under another domain, its not possible actually to stop a page from unloading. Having something like that,  would allow malicious sites to &#8220;trap&#8221; a user indefinitely.</p>
<p>I would love to hear any other suggestions regarding iframe breakout you may have dear readers.</p>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/how_to_prevent_iframe_breakaway.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting an Internet Connection With Javascript</title>
		<link>http://initbinder.com/articles/detecting_an_internet_connection_with_javascript.html</link>
		<comments>http://initbinder.com/articles/detecting_an_internet_connection_with_javascript.html#comments</comments>
		<pubDate>Sat, 24 Jan 2009 07:26:00 +0000</pubDate>
		<dc:creator>Alexander Zagniotov</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[ping]]></category>

		<guid isPermaLink="false">http://javabeans.asia/2009/01/24/detecting_an_internet_connection_with_javascript.html</guid>
		<description><![CDATA[The other day I was developing small client-server application where I needed to check using Javascript on the client&#8217;s side whether active Internet connection exists, before submitting request to the server. Javascript does not allow you to do ping, and &#8230; <a href="http://initbinder.com/articles/detecting_an_internet_connection_with_javascript.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The other day I was developing small client-server application where I needed to check using Javascript on the client&#8217;s side whether active Internet connection exists, before submitting request to the server.</p>
<p>Javascript does not allow you to do ping, and even so many websites protect against ping requests (ICMP echo), so I had to come up with some alternatives.</p>
<p>One of the nice solutions that I have found is to create an Image object and to specify as image source, URL to an image located on a remote server. Then to test, if the newly created Image object has height or width greater than zero.</p>
<p>If it is greater, what it means is that there is active Internet connection, since it was possible to create Image object using image or icon located on a remote server.</p>
<p>The downside here is that path to the image or image filename may change in the future on the target remote server, and as a result of that your Javascript function will stop working.</p>
<p>While thinking what image should I link to, I decided to use Google&#8217;s favicon. I tend to think that the favicon is not something that is going to change very often. I also considered to use Goggle logo, but favicon is much smaller in size.<br />
(Another thing worth remembering is to allow some time to retrieve the remote image, which is another reason why I went for the favicon).</p>
<p>The solution is:</p>
<p>[java]<br />
function testConnection() {<br />
   var googleFavIcon = new Image();<br />
   googleFavIcon.src =<br />
               &quot;http://www.google.com/favicon.ico&quot;;</p>
<p>   if(googleFavIcon.height&gt;0)  {<br />
       //do something<br />
    }<br />
    else {<br />
      //warn user<br />
    }<br />
}<br />
[/java]</p>
<p>Just keep in mind, that the remote image is cached once you got it. If you decide to test connection again, you have to make sure that you are not using the cached image, but trying to retrieve it again from the remote server. To prevent caching, you can add some random parameter to the URL:</p>
<p>[java]</p>
<p>http://www.google.com/favicon.ico?param=[random-value]</p>
<p>[/java] </p>
]]></content:encoded>
			<wfw:commentRss>http://initbinder.com/articles/detecting_an_internet_connection_with_javascript.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  initbinder.com/categories/javascript/feed ) in 0.29836 seconds, on May 18th, 2012 at 1:59 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 18th, 2012 at 2:59 pm UTC -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  initbinder.com/categories/javascript/feed ) in 0.00107 seconds, on May 18th, 2012 at 2:14 pm UTC. -->
