Kurinchi Blogger Scribbles …


Posts Tagged ‘jQuery’

Oct 01
2009

Javascript code organization for optimized performance

Last updated: October 1st, 2009

Knowing how javascript code gets executed in a browser will help us organize the libraries or functions for better performance.

Javascript unlike the server side scripting languages like PHP, ASP, Perl is not compiled at the server side. It is sent as-is from the server to the browser client and it is the browser that interprets the code at the client side.

The total size of the Javascript code and its organization will have a significant effect on the pages served at the client side which in turn will affect the performance of the page.

Organize the libraries in such a fashion that you only have the needed functions associated with the page. You can consider this point right at the time of creating your template pages. This will reduce the number of javascript pages that are called from one page. (more…)

Sep 05
2009

How to open ALL external web sites or references in a NEW window?

Last updated: September 24th, 2009

Using JQuery to open external links in new windows

Earlier we used to write a string of code in javascript to enable opening external references in a new window in addition to modifying the html code

With JQuery, this can be done with one line of code as shown below

$(document).ready(function(){
    $("a[@href^='http']").attr('target','_blank');
});

The above line checks for occurences http in a tag and if a link has “http” in it, JQuery opens the link in a NEW window.

According to W3C standards, the target attribute has been removed from xhtml 1.1 specification.

Sample script to open external links in New Window

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">
<head>
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function(){
    $("a[href^='http']").attr('target','_blank');
});
</script> 
</head>
<body>


Testing the pages - Open Links in new <a href="http://yahoo.com">window</a>.

<h1><a href="http://www.kurinchilion.com">Kurinchilion</a></h1>
</body>
</html>
Jun 11
2009

JQuery: Showing a progress image while processing background task

Last updated: June 11th, 2009

I thought to write a simple example to show a progress bar or a gif image showing a that a task is happening at the background using a jquery function.

i) Include jquery script file in the header section and the following code in the head

<script language="javascript">
$(document).ready(function(){
    $('#progress').hide();
    $("#main a.bgdiv").click(function(){
        $("#progress").show("slow");
        $("body").load($(this).attr('href'));
        return false;
    });
});
</script>

(more…)

Jun 06
2009

jQuery extension Impromptu

Last updated: June 9th, 2009

This is an easy and elegant way to prompt user messages or to seek user inputs. The author of this tool had cleanly explained its various usage by giving examples which is again easy to follow.

Check out the extension at http://trentrichardson.com/Impromptu/index.php


Valid HTML 4.01 Strict  Valid HTML 4.01 Strict