Open all external links in new window or tab using jquery

In this programming tutorial we will learn how to open all external links in new window or tab using jquery. External links should be open in new window or tab because we should not lost the focus of user from our website if he clicks the external link. We all know that to open a link in a new window, we have to set the target attribute as '_blank' in our HTML link tag. But this process is very time consuming if we have huge number of external links in our page. To get rid of this problem just have a look over following code snippet.

Open all external links in new window using jquery
Put this script just before <body> tag
<script language="javascript" type="text/javascript">
$("a[href*='http://']:not([href*='"+location.hostname.replace("www.","")+"'])").each(function() {
$(this).attr('target', "_blank");
    });
</script>
That's it. And if you want to add css class to external hyperlinks then use this code
<script language="javascript" type="text/javascript">
$("a[href*='http://']:not([href*='"+location.hostname.replace("www.","")+"'])").each(function() {
$(this).addClass('externalLinkClass').attr('target', "_blank");
    });
</script>

And here is the css class
.externalLinkClass {
    color:red;
    font-weight:bold;
    text-decoration:none;
}

So that's it.
I Love your feedback.

Read more...

Check if there is an attribute on an element using jquery

In this programming tutorial we will learn how to check if there is an attribute on an element or not using jquery. We will use attr() function of jquery, yeah jquery because it is very powerful for performing operations over DOM. So let's have a look over code snippet given below in which we will check whether txtName textbox contains name attribute or not.

var attrExists = $("#txtName").attr("name");

// In some browsers, "attrExists" is undefined; for others,  "attrExists" is false. 
// Check for both.
if (typeof attrExists!== 'undefined' && attrExists !== false) {

    // Attribute Exists
}

So that' it.
I love your feedback.




Read more...

Check if an element contains attribute or not using jquery

In this programming tutorial we will learn how to check if an element contains attribute or not using jquery. Using built-in jquery's function we can check if an element contains particular attribute or not but we cannot check if an element contains at least one attribute or not. So let's start

Check if an element contains attribute or not using jquery
function hasAtleastOneAttribute(selector) {
    var attributeExists = false;
    $(selector).each(function(index, element) {
        if (element.attributes.length > 0) {
            attributeExists = true;
            return false; // breaks out of the each once we find any attribute
        }
    });
    return attributeExists;
}

Let's have a look over how to call it.
if (hasAtleastOneAttribute('.myClass')) {
    // Write your stuff here
}

So that's it.
I love your feedback.
Read more...

Sort varchar date in ms sql server

In this programming tutorial we will learn how to sort the varchar date in ms sql server. I face the sorting problem of varchar date couple of days ago and then I decided to write a tutorial in it. I have a column registered_date of datetime datatype in users table; in that column the values are stored definitely in this format 2011-07-21 00:00:00.000. I wanted to get the distinct date in mm/dd/yyyy format and also wanted to sort the date(the purpose of this tutorial) according to my need.

I have easily converted the registered_date column of datetime into varchar and display date in mm/dd/yyyy format by using convert(varchar(10),registered_date,101) function but I failed to sort the date, also I failed to get the distinct date, like illustrated in following picture.
sort varchar date in ms sql server


So for fixation of this problem, I have written following query

Learn How to sort varchar date in ms sql server
Select Distinct convert(datetime,convert(varchar(10),registered_date,101)),   
convert(varchar, registered_date,101) As registered_date
FROM users Where Deleted ='false' order by convert(datetime,convert(varchar(10), registered_date,101)) desc

Output will be:-
2011-07-21 00:00:00.000      07/21/2011
2011-07-19 00:00:00.000      07/19/2011
2011-07-18 00:00:00.000      07/18/2011
2011-07-16 00:00:00.000      07/16/2011
2011-07-13 00:00:00.000      07/13/2011
2011-07-12 00:00:00.000      07/12/2011
2011-07-08 00:00:00.000      07/08/2011
2011-05-03 00:00:00.000      05/03/2011
2011-04-28 00:00:00.000      04/28/2011
2011-04-27 00:00:00.000      04/27/2011
2011-04-14 00:00:00.000      04/14/2011
2011-04-07 00:00:00.000      04/07/2011
2011-04-01 00:00:00.000      04/01/2011
2011-03-29 00:00:00.000      03/29/2011

The query is self explanatory; I have converted the registered_date column into varchar and then again into datetime to get the distinct date and this first column is very important in this scenario which look extra in first sight because using this first extra column i was able to sort the date :).

So that’s it.
I Love your feedback


Read more...

The .whatever address is coming soon to the Web

SINGAPORE — 25 years after the creation of ".com," the agency that provides Internet addresses is loosening its rules and allowing suffixes named after company, hobbies, brands, political causes and just about anything else you want. You website name can be www.yourwebsite.whatever. Yeah instead of .com you can use anything that you want.

Apple could register addresses ending in ".ipad," Citi and Chase could share ".bank" and environmental groups could go after ".eco.".

It's the biggest and widest change to the system of Internet addresses since it was created in 1984.

More than 300 suffixes are available today, but only a handy, such as the familiar ".com" and ".net" are open for general use worldwide. Hundreds of new suffixes could be established by late next year, thousands in years to come.

"This is the start of a totally new era for the Internet," said Peter Dengate Thrush, chairman of the Internet Corporation for Assigned Names and Numbers, the California nonprofit organization in charge of Internet addresses.

The novelty addresses will be costly — $185,000 to apply and $25,000 a year to maintain one. A personal address with a common suffix such as ".com" usually costs less than $10 a year.

ICANN says it costs tens of millions of dollars to write the guidelines for suffixes, review applications and resolve any disputes. Even with the hefty fees, the organization says it plans only to break even. It's also setting aside up to $2 million to subsidize applications from developing countries.

The expansion plan, which runs about 350 pages, took six years to develop.

Before 1998, the United States, which paid for most of the early Internet, was in charge of handing out Internet suffixes. ICANN, which has board members from every inhabited continent, was a way to take the administrative burden off the united states government.
The .whatever address is coming soon to the Web

ICANN was always supposed to expand the number of available Web suffixes. But in past the progress was slow because of concerns that new ones could infringe on trademarks, be obscene or give a platform to hate groups. Competing interests wrestled with ICANN over guidelines.

ICANN has come up with procedures for any party to object to applications for trademark, or other reasons.

Internet addresses, technically known as domain names, tell computers where to find a website or send an email message. Without them, people would have to remember clunky strings of numbers such as "165.1.59.220" instead of "ap.org."

But the addresses have grown to mean much more. Amazon.com has built its brand on one, and bloggers take pride in running sites with their own domain names, uncluttered by the names of hosting services.

The address expansion could create new opportunities for companies to promote their brands and allow all sorts of niche communities to thrive online. But they could create confusion, too.

And they might not make much difference. More and more people online find what they're looking for by typing a term into a search engine, not tapping out a full address. Or they use an app and don't type anything.

ICANN will start taking applications for new suffixes Jan. 12. Approval of individual applications is expected to be quick if there are no challenges for trademark, morality or other reasons. Proposals that are challenged would have to undergo more thorough reviews, including possible arbitration to decide on the merits of claims.

High-profile entertainment, consumer-goods and financial-services companies will likely be among the first to apply for the new suffixes to protect their brands.

Canon Inc., the camera and printer company, already plans to apply for ".canon." And Apple could go after not just ".apple," but also ".ipad" and ".iphone." Apple had no comment Monday.

Groups have already become to get ".sport" for sporting sites, and two conservationist groups separately are seeking the right to operate an ".eco" suffix. Trade groups for bankers and financial-services companies are jointly exploring applications for ".bank," ".insure" and ".invest" for their member companies.

Smaller companies stand to benefit, too. A florist called Apple can't use "Apple.com" because the computer company has it. Previously, the shop might have registered a longer, clunky address. Now it can just be "Apple.flowers."

Of course, a small florist might not be able to afford an expensive suffix. But an entrepreneur or a trade group might, and it could sell individual addresses ending in ".flowers" for $10 or $100 a pop. A successful suffix owner could make millions, much more than what it pays in application and annual fees.

When two or more groups have a legitimate claim to an address, ICANN expects them to work it out on their own. If they can't, the nonprofit will auction the suffixes.

"Things are going to have to be decided, like 'Who's a better guardian for .golf?' The PGA or some global group?" said Jeremiah Johnston, chief operating officer at Sedo.com, which helps companies resell domain names.

Sedo brokered the sale of Sex.com late last year for $13 million, a record for a domain name. Despite the availability of new suffixes, Johnston doesn't expect the value of existing ".com" names to diminish. That's based on the limited number of additions to the system since 2000.

"Even though the new extensions come around, the ones that are most rooted and most popular in the minds of consumers, their value has only gone up," Johnston said.

So that's it. Think your suffix :)
Source by : msnbc
Read more...

Get ip address in asp.net using c#

In this programming tutorial we will learn how to get ip address in asp.net with c#. I have already written same tutorial for php. In asp.net it is also very easy to find ip address no matter whether user is behind the proxy or not, you can easily track the user in asp.net. So let's have a look over the following code snippet.
How to get ip address in asp.net using c#
//To get the ip address of the machine and not the proxy use the following code     
            string strIPAddress = Request.UserHostAddress.ToString();
            strIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (strIPAddress == null || strIPAddress == "")
            {
                strIPAddress = Request.ServerVariables["REMOTE_ADDR"].ToString();
            }

So that's it.
I love your feedback.

Read more...

Install PHP on Windows 7 with IIS 7 via FastCGI

In this programming tutorial, we will learn how to install and configure PHP on windows 7 with IIS 7 via FastCGI. I have already written a tutorial about Installing php on windows but now this tutorial is not handy after release of php 5.3 version because php5isapi.dll is no longer available in the php releases starting from 5.3. So my recommendation is with the world’s recommendation and that is to use "FastCGI". Please consider following points before installing PHP on Windows 7.
  1. First of all check the system type; either it is 32 bit or 64 bit. X86 means 32 bit. X64 means 64 bit. Download the appropriate php version according to your system type.
  2. If you are using PHP with IIS you should use the VC9 versions of PHP.
  3. A Thread Safe version should be used if you install PHP as an Apache module. The Non Thread Safe version should be used if you install PHP as a CGI binary.
  4. Non-thread-safe build of PHP is recommended for PHP 5.3 version when using IIS. The non-thread-safe builds are available at » PHP for Windows: Binaries and Sources Releases.

Note: 

VC9 Versions are compiled with the Visual Studio 2008 compiler and have improvements in performance and stability. The VC9 versions require you to have the » Microsoft 2008 C++ Runtime (x86) or the » Microsoft 2008 C++ Runtime (x64) installed. If you have visual studio 2008 install then you don't have to install Microsoft 2008 C++ Runtime.
 
What is FastCGI?
FastCGI is a standard protocol that allows the CGI executable files for application frameworks to interface with the Web server. It is different to the standard CGI protocol in that FastCGI reuses CGI processes for multiple requests, which provides a significant performance boost as compared to CGI. Support for IIS FastCGI enables IIS to host normal CGI programs like PHP or Ruby on Rails by using the FastCGI protocol, and to offer high performance and stability for production deployment of such application frameworks.

For having the IIS FastCGI support, you must have following things:
  • IIS Web server
  • IIS FastCGI extension
  • CGI program (such as php-cgi.exe)
The Web server dispatches HTTP requests to your application to the FastCGI component, which in turn launches the CGI program executable, and forwards the request for processing. Once the request is finished and the response is returned back to the server and sent to the client, the CGI process is reused for a subsequent request. This helps to avoid the high performance penalty of starting a new process for each request, which results in better performance and scalability in a production environment. Now let’s come to the topic.

Install PHP on Windows 7 with IIS 7 via FastCGI

First of all, definitely you need to have PHP. Go to the PHP download page and get the latest non-thread-safe ZIP archive of windows binaries for Windows. As of writing this, the package is called "PHP 5.3 (5.3.6) Non-thread-safe zip package". Unzip the archive to a folder on your hard disk. I use C:\php5.

In the latest version of php, you will not find any php.ini-recommended file in php directory. php.ini-recommended is replaced by php.ini-development and php.ini-production files. php.ini-production is used for production systems; for development systems you should use php.ini-development.

Open the php.ini-development and save as php.ini in the same folder and then use the following configuration setting.

Uncomment cgi.force_redirect by removing preceding; and then set it as cgi.force_redirect = 0

This directive is required for running under IIS. It is a directory security facility required by many other web servers. However, enabling it under IIS will cause the PHP engine to fail on Windows.
It is the minimum setting you need to change so that PHP can work with IIS.

Additionally, you may want to use
Uncomment cgi.fix_pathinfo by removing preceding; and then set it as cgi.fix_pathinfo = 1

This lets PHP access real path info following the CGI Spec. The IIS FastCGI implementation needs this set.

Uncomment fastcgi.impersonate by removing preceding; and then set it as fastcgi.impersonate = 1

FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under.

Uncomment extension_dir by removing preceding; and then set it as extension_dir=C:\php5\ext.

The extension_dir needs to point to the directory where PHP extensions files are stored. The path can be absolute (i.e. "C:\PHP5\ext") or relative (i.e. ".\ext"). Extensions that are listed lower in the php.ini file need to be located in the extension_dir.

Note: - It is better approach to save php.ini in c:/windows as well.

PHP is now setup on your system. The next step is to choose a web server, and enable it to run PHP. We will go with IIS 7.

Internet Information Services (IIS) 7 is available on Windows Vista, Windows 7, and Windows Server 2008.

You probably heard a lot of bad things about IIS, from various groups. If you were holding off using IIS because of that well now is the time to re-evaluate IIS with version 7. A lot of the problems that plaques IIS were cured way back in IIS 5. Introduced in IIS 7 was a new architecture similar to Apache with its modules. Everything in IIS 7 is a module, an extension that can be removed. Just need a basic HTTP server? No problem! Just remove or deactivate everything but the HTTP service module.

Now let’s install IIS 7 if it is not installed in Windows 7. Go to the Start/Control Panel/Programs/Turn Windows Features on or off and check on the Internet Information Services entry. Activate the World Wide Web Services/Application Development Features/CGI node and also Web Management Tools/IIS Management Console (the latter not shown in the figure).

Installing PHP on Windows 7 - Step 1

Now, start the IIS Management Console; Open up the start menu, press windows+r to bring run dialog, type inetmgr and hit Enter. There, navigate to the Sites/Default Web Site/Handler Mappings node and double-click on the Handler Mappings entry.

Installing PHP on Windows 7 - Step 2


As a result of this, the Actions panel on the right hand side changes. You will now see an option called Add Module Mapping. Clicking on it brings a dialog which you fill out as you can see in the following figure (you may need to adapt the path used to your local system).

Installing PHP on Windows 7 - Step 3


If you do not see the FastCgiModule entry, you probably forgot to check the CGI node when installing IIS. Otherwise, close the Add Module Mapping dialog by pressing OK button. You need to confirm that you want to create a FastCGI application; click Yes.

Installing PHP on Windows 7 - Step 4


If you don't want to save php.ini in c:\windows then restart the IIS else Reboot your pc.

Finally, create a .php page and put it in the root folder (wwwroot) of the IIS site by default C:\Inetpub\wwwroot, e.g. phpinfo.php with a simple phpinfo() call in it like the code given below.
<?php
phpinfo();
?>

Call this page using http://localhost/phpinfo.php, and you are done!

So that's it. Later on I will update this tutorial and will tell you how to configure mysql with php 5.3+ versions running on IIS 7. So stay tuned.

I love your feedback.

Read more...

How to check if checkbox is checked or not using jquery

In this programming tutorial you will learn how to check if checkbox is checked or not using jquery. Jquery is a best javascript library to deal with dom's elements. There are various methods in jquery for this. Let's have a look over it.
How to check if checkbox is checked or not using jquery

//Method 1
if($('#checkBox').attr('checked'))
{
//Your code will come here
} 
else
{
//Your code will come here
}

//Method 2 
if($('#checkBox').is(':checked'))
{
//Your code will come here
}
else
{
//Your code will come here
} 

The above two methods return true or false. Return true if checkbox is checked or false if it is not checked. The third method iterates though all checkboxes with checked attribute defined and performs some action.

So that's it.
I love your feedback.
Read more...

How to remove the last comma from string and replace it with a period in Javascript?

In this programming tutorial you will learn how to remove the last comma from string and replace it with a period in Javascript. I will use regular expression for it. Let's have a look over the following code snippet
How to remove the last comma from string and replace it with a period in Javascript?

str2 will contain the string a,s,d,f,g. I hope you will find this tutorial very handy.

So that's it. I love your feedback.
Read more...

How to remove "," from a string in javascript

In this programming tutorial you will learn how to remove "," from a string in javascript. Couple of days i got requirement to remove "," from the string which is
a,b,c,d,e,f,g,h and make it abcdefgh. I have done it by using javascript. Let's have a look over how to do so
<script type="text/javascript">
        var str1 = "a,b,c,d,e,f,g,h";
        var str2 = str1.replace(/\,/g,"");
    </script>
str2 will contain the string abcdefgh.I hope you will find this tutorial very handy.
So that's it. I love your feedback.
Read more...

How to check if table exists or not in ms sql server database

In this programming tutorial you will learn how to check if table exists or not in ms sql server database. Doing so is quite easy in ms sql server. sp_help command is use for this purpose. So let's have a look over it.
How to check if table exists or not in ms sql server database
sp_help yourtblname
Yeah that's it. If table exists then this command will give you the structure of your table else it will will give you the following error

The object 'blah blah' does not exist in database 'blah blah' or is invalid for this operation.

I love your feedback.
Read more...

How to check if stored procedure exists or not in ms sql server database

In this programming tutorial you will learn how to check if stored procedure exists or not in ms sql server database. It is quite easy in ms sql server with the help of a sp_helptext command. So let's have a look over it.
How to check if stored procedure exists or not in ms sql server database
sp_helptext yourspname
Yeah that's it. If stored procedure exists then this command will give you the text of stored procedure else it will will give you the following error

The object 'blah blah' does not exist in database 'blah blah' or is invalid for this operation.

I love your feedback.
Read more...