Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, January 11, 2010

JavaScript for getting user details

If you want to get user detail through java script, use this script


<!-- 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

Some times we can see a add to favorite link in many sites. When you click on this link, the "Favorites" window pop-ups asking if you would like to add the site to the list.
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

This a simple example of drag n drop using javascript.


<!-- TWO STEPS TO INSTALL DRAG-N-DROP:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->



<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
N = (document.all) ? 0 : 1;
var ob;
function MD(e) {
if (N) {
ob = document.layers[e.target.name];
X=e.x;
Y=e.y;
return false;
}
else {
ob = event.srcElement.parentElement.style;
X=event.offsetX;
Y=event.offsetY;
}
}
function MM(e) {
if (ob) {
if (N) {
ob.moveTo((e.pageX-X), (e.pageY-Y));
}
else {
ob.pixelLeft = event.clientX-X + document.body.scrollLeft;
ob.pixelTop = event.clientY-Y + document.body.scrollTop;
return false;
}
}
}
function MU() {
ob = null;
}

if (N) {
document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}
document.onmousedown = MD;
document.onmousemove = MM;
document.onmouseup = MU;
// End -->
</script>
</HEAD>



<!-- STEP TWO: Copy this code into the BODY of your HTML document -->



<BODY>

<div id="s" style="position:absolute;left:50;top:300;">
<img src=~/img/cards/spades.gif name="s">
</div>

<div id="d" style="position:absolute;left:50;top:350;">
<img src=~/img/cards/diamonds.gif name="d">
</div>

<div id="c" style="position:absolute;left:100;top:300;">
<img src=~/img/cards/clubs.gif name="c">
</div>

<div id="h" style="position:absolute;left:100;top:350;">
<img src=~/img/cards/hearts.gif name="h">
</div>

Just click and hold the 4 suit images to the left and then you can move them around the page!

</body>
</html>

original post

Friday, August 28, 2009

Refreshing a asp.net web form automaticaly

This means: forcing a page postback or redirect from a client browser without explicit user input.

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

This javascript code checks whether the checkDate is between beginDate and endDate and generates a MessabeBox



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

The following code snippet allows user to enter only digits.

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.