Monday, January 11, 2010
JavaScript for getting user details
<!-- ONE STEP TO INSTALL IP ADDRESS:
1. Copy the coding into the HEAD of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
// http://www.kdcgrohl.com
// Depending on your server set-up,
// you may need to use the ".shtml"
// extension [instead of the "html"
// or "htm"] as the script uses Server
// Side Includes. To display in the
// title bar, exclude the
//"<title></title>" code from the page.
// This part gets the IP
var ip = '<!--#echo var="REMOTE_ADDR"-->';
// This part is for an alert box
alert("Your IP address is "+ip);
// This part is for the status bar
window.defaultStatus = "Your IP address is "+ip;
// This part is for the title bar
document.write("<title>Your IP address is "+ip+"</title>");
// End -->
</script>
<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.09 KB -->
Thursday, January 7, 2010
Add to favorite link script
Let us first see the advantages of adding such a link:
If visitors really like your site, they can easily add it to their favorites list through the normal process - Under Internet Explorer, click on the "Favorites" menu item and then on "Add to Favorites...".
However, they might just forget about this or they just might feel lazy (...you now what I mean). If you have an "Add To Favorites" link, you not only remind the visitors of the favorites folder but also prompt them to add your site and this just takes one click.
Here we use a little JavaScript and tie it up to the HREF tag of the link and here is the JavaScript function code:
function addfav()
{
if (document.all)
{
window.external.AddFavorite
("http://www.addictdotnet.blogspot.com","Dot the Net")
}
}
Note: The javascript statement "window.external.AddFavorite(..." should be a single line
The part in red color in the above code is the URL and the blue is the Name you want to give to the link.
The function can be placed inside the document head or an external .js file and will be called from the link as:
Add To Favorites
Tuesday, January 5, 2010
Java Script Drag anddrop example
Friday, August 28, 2009
Refreshing a asp.net web form automaticaly
Why would you want to do that? The main reasons are:
Auto-redirecting to a new URL after a brief time period
Refreshing page information periodically
Maintaining a valid session state indefinitely
Forcing a specific process to run on the server when the client session has expired.
The following methods are the constructs we have used in our web development projects:
HTML header refresh tag
The most common and best known way - a tag of the following format is placed in the HTML section of the page:
<meta http-equiv="refresh" content="8;url=http://dotnet.org.za/">
where '8' refers to the number of seconds that will elapse before the page is refreshed;
'url' is the new url redirect to. It can be excluded which means the current page will be reloaded.
This construct is useful if you have one or two pages which have to auto-refresh, and works for any HTML content type forms. The downside is the refresh interval cannot be set dynamically, and if you are testing for session timeouts on your site, you'll have to embed this construct in every page of the site.
Response.AppendHeader method
ASP.NET provides the AppendHeader method to the Response object. Typically the page refresh can be set as follows in an ASP.NET webform (in C#):
this.Response.AppendHeader("Refresh",
Convert.ToString(Session.Timeout * 60 + 5));
Here the page refresh is set to 5 seconds after the client session timeout setting specified in the web.config file.
This construct is useful as it can be placed in a base webform OnLoad() or Page_Load() response method. All derived webforms will then have the same page refresh setting when they are loaded. Obviously, if the timeout value is changed in the web.config file, no modification is required in this code and everything still works fine.
Page OnLoad method script
The same thing can be done by setting a script for the client-side HTML using the HtmlGenericControl.Attributes collection:
string onload = "window.setTimeout(
'window.location.href=window.location.href'," +
Convert.ToString( (Session.Timeout * 60 + 5) * 1000) + ");";
this.body.Attributes.Add("onload", onload);
Unfortunately, to get this to work you need to add the following attribute to the tag in the HTML:
runat="server"
and the following member in the webform code-behind class:
protected System.Web.UI.HtmlControls.HtmlGenericControl body;
Hmmm - so why do this, if it means that we have to fiddle with the HTML?
In our experience, certain ASP.NET controls in the webform actually kills the working of the previous two constructs - but this method always seems to work....regardless...in Internet Explorer...
Saturday, August 15, 2009
Check if date and time is between two date and times
function dateWithin(beginDate,endDate,checkDate) {
var b,e,c;
b = Date.parse(beginDate);
e = Date.parse(endDate);
c = Date.parse(checkDate);
if((c <= e && c >= b)) {
return true;
}
return false;
}
// This will alert 'false'
alert(dateWithin('12/20/2007 12:00:00 AM','12/20/2007 1:00:00 AM','12/19/2007 12:00:00 AM'));
Thanks
Happy Programming.
Thursday, July 23, 2009
Enter only digits in Textbox
function AcceptDigits(e)
{
var charCode = (navigator.appName == "Netscape")? e.which : e.keyCode;
if(e.shiftKey)
{
return false;
}
if( (charCode > 47 && charCode < 59) || charCode==8 || charCode==37 || charCode==39 || charCode==46 || charCode==9 || charCode==36 || charCode==35)
{
return true;
}
else
{
return false;
}
}
Wednesday, July 1, 2009
Text Link Ad Rotation using jQuery
People who have been monetizing their sites need no introduction to Text Link Ads. In simple words, Text Link Ads are Hyperlinks sponsored by Advertisers. When a user clicks on these hyperlinks, they are sent to the sponsor’s website.
In this post, we will see how to rotate Text Link Ads on the same position. I will use the Cycle Plug-in for this purpose, since it accomplishes this task in just one line of code. Download the Cycle Plugin.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Text Link Ad Rotationtitle>
<script type="text/javascript"
src="http://code.jquery.com/jquery-latest.js">
script>
<script type="text/javascript"
src="Scripts/jquery.cycle.all.min.js">
script>
<script type="text/javascript">
$(document).ready(function() {
$('#Links').cycle('fade');
});
script>
<style type="text/css">
body
{
font-size:13px;
font-family:"Lucida Grande", "Lucida Sans Unicode";
color:#444444;
}
style>
head>
<body>
<div id="Links">
<a href="http://www.niksgaur.blogspot.com">>My Software and web development Experiencea>
<a href="http://www.engcolgs.blogspot.com">My College Lifra>
<a href="http://authornitin.blogspot.com">Canvassa>
div>
body>
html>
You can use the Effects Browser page to preview all the effects that are available with the Cycle Plug-in.
Note: To rotate ASP.NET Hyperlinks, replace the HTML links with the following:
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="http://jquery.com">jQueryasp:HyperLink>
There’s no need to change any other code since this asp.net control gets rendered as html A tag
You can see a live demo of the example given in this post over here. The Link Rotates after every few seconds.