JavaScript Trim, LTrim, RTrim Functions using Regular Expressions

Tuesday, July 28, 2009

function jsTrim(stringToTrim)
{
return stringToTrim.replace(/^\s+\s+$/g,"");
}

function jsLtrim(stringToTrim)
{
return stringToTrim.replace(/^\s+/,"");
}

function jsRtrim(stringToTrim)
{
return stringToTrim.replace(/\s+$/,"");
}


Usage:
alert(jsTrim("     Webpage Tips     "));
alert(jsLtrim("     Webpage Tips"));
alert(jsRtrim("Webpage Tips     "));

Read more...

HTML vs XHTML

Monday, July 13, 2009

This specification defines an abstract language for describing documents and applications, and some APIs for interacting with in-memory representations of resources that use this language.



The in-memory representation is known as "DOM5 HTML", or "the DOM" for short.

There are various concrete syntaxes that can be used to transmit resources that use this abstract language, two of which are defined in this specification.



The first such concrete syntax is "HTML5". This is the format recommended for most authors. It is compatible with all legacy Web browsers. If a document is transmitted with the MIME type text/html, then it will be processed as an "HTML5" document by Web browsers.



The second concrete syntax uses XML, and is known as "XHTML5". When a document is transmitted with an XML MIME type (page 29), such as application/xhtml+xml, then it is processed by an XML processor by Web browsers, and treated as an "XHTML5" document. Authors are reminded that the processing for XML and HTML differs; in particular, even minor syntax errors will prevent an XML document from being rendered fully, whereas they would be ignored in the "HTML5" syntax.



The "DOM5 HTML", "HTML5", and "XHTML5" representations cannot all represent the same content. For example, namespaces cannot be represented using "HTML5", but they are supported in "DOM5 HTML" and "XHTML5". Similarly, documents that use the noscript feature can be represented using "HTML5", but cannot be represented with "XHTML5" and "DOM5 HTML". Comments that contain the string "-->" can be represented in "DOM5 HTML" but not in "HTML5" and "XHTML5". And so forth.

Read more...

CSS Rounded Buttons

Friday, July 10, 2009

This technique is simple and effective way to have buttons with nice rounded edges using plain CSS without any Javascript usage.

This method was tested on these common browsers:

  • Internet Explorer
  • Mozilla Firefox
  • Opera
  • Safary
  • Google Chrome

CSS Code:

.button {
cursor: pointer;
display: -moz-inline-box;
display: inline-block;
padding-left: 5px;
padding-bottom: 1px;
line-height: 19px;
background-position: lef top;
background-repeat: no-repeat;
background-image: url(btn-left.gif);

}

.button span {
padding-left: 10px;
display: -moz-inline-box;
display: inline-block;
padding-right: 15px;
padding-bottom: 1px;
line-height: 19px;
background-position: right top;
background-repeat: no-repeat;
background-image: url(btn-right.gif);
}


<a class="button" href="http://about-jsharp.blogspot.com/"><span>Button1</span></a>

Click here to download sample code with images

Read more...

How to calculate download Speed using C#.net and Java Script code

Wednesday, July 8, 2009

Using C#.Net code

private void CalculateDownloadTime(double fileSizeMB,double fileSizeKB,int speed,ref int timeHour,ref int timeMinute,ref int timeSec)
{
double downloadTime = 0;

if (fileSizeMB != 0)
{
downloadTime = (fileSizeMB * Constant.FILE_SIZE_KB * 8.192) / speed;
}
else if (fileSizeKB != 0)
{
downloadTime = (fileSizeMB * 8.192) / speed;
}

timeHour = Convert.ToInt32(downloadTime) / 3600;
timeMinute = (Convert.ToInt32(downloadTime) % 3600) / 60;
timeSec = Convert.ToInt32(downloadTime) % 60;
}



Example to call above function:
int timeHour =0;
int timeMinute =0;
int timeMinute =0;
CalculateDownloadTime(30,0,56, ref timeHour, ref timeMinute, ref timeMinute);

Using Java Script
<script type="text/javascript">
var speeds = new Array(
new Array("9.6 Modem", "9.6"),
new Array("14.4 Modem", "14.4"),
new Array("19.2 Modem", "19.2"),
new Array("28.8 Modem", "28.8"),
new Array("33.6 Modem", "33.6"),
new Array("56 Kb Modem", "56"),
new Array("Single Channel ISDN (64Kbps)", "64"),
new Array("Dual Channel ISDN (128Kbps)", "128"),
new Array("Asymmetric DSL (ADSL)", "384"),
new Array("Single-pair HDSL (S-HDSL)", "768"),
new Array("Consumer DSL (CDSL)", "1024"),
new Array("T1", "1544"),
new Array("HDSL", "1544"),
new Array("T3", "46080"),
new Array("Very high-speed DSL (VDSL)", "52224"),
new Array("OC1", "53248"),
new Array("100 Base-T (fast ethernet)", "102400"),
new Array("ATM", "158720"),
new Array("OC3", "159744"),
new Array("1000 Base-T", "1024000")
);

function compute (form, scale)
{
if (form.size == null form.size.length == 0)
{
alert("Please enter a valid filesize.");
return;
}

var size = parseFloat(form.size.value);
for (var i = 1; i <= speeds.length; i++)
{
var time = size * scale * 8.192 / speeds[i - 1][1];
var hours = Math.floor(time / 3600);
var minutes = Math.floor((time % 3600) / 60);
var seconds = Math.floor(time % 60);
form[i + "hour"].value = hours;
form[i + "minute"].value = minutes;
form[i + "second"].value = seconds;
}

}
</script>


Example to call above (compute) function:
For file Size MB --> compute(30,1024)
For file size KB --> compute(30,1)

Read more...

How to move web page division on mouse scroll

Monday, July 6, 2009

How to move web page division on mouse scroll (up/down)

Following code is an example to move left side portion of the web page on mouse scroll.

The division which you are going to move should be placed before java script; this code can implement in Java or .Net application, this java script function is compatible with Netscape, Mozilla and IE browsers.

Note: This code will activate only when you have horizontal scroll bar in your web page.


//Sample division to move
<div id="divTopLeft" style="position:absolute;left:10;top:200;width:167;">
<table border="1" width="159" height="550" bgcolor=Pink bordercolor="black" cellspacing="0" cellpadding="0">
<tr>
<td bordercolor="Pink">
<font color="blue">Your text should go here..</font>
</td>
</tr>
</table>
</div>
//Java script function to move above division up and down
<script type="text/javascript">
function FloatTopLeft()
{
//Set the start X and Y position for division
var startX = 622, startY = 220;
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";
function ml(id)
{
var el=d.getElementById?d.getElementById(id):d.all
?d.all[id]:d.layers[id];
if(d.layers)el.style=el
el.sP=function(x,y)
{
this.style.left=x+px;this.style.top=y+px;};
el.x = startX; el.y = startY;
return el;
}
window.stayTopLeft=function()
{
var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
var dY = (pY > startY) ? pY : startY;
ftlObj.y += (dY - ftlObj.y)/8 + 1;
ftlObj.sP(ftlObj.x, ftlObj.y);
setTimeout("stayTopLeft()", 20);
}
ftlObj = ml("divTopLeft");
stayTopLeft();
}
FloatTopLeft();
</script>


Read more...

How to Lock the DeskTop in different Way ( Something New)

This is a interesting piece of info that you can use to lock your work-stations without using the combo key "CTRL- ALT- DEL"

If CTRL-ALT-DELETE seems like too much of a hassle, try this instead:

  1. Right click an empty spot on the desktop, point to New and click Shortcut.

  2. In the Create Shortcut dialog box, type the following into the Type the location of the item text box: "rundll32 user32.dll,LockWorkStation" // remove quotes while typing

  3. Click Next.

  4. In the Select a Title for the Program dialog box, type "Lock Desktop" in
    the Type a name for this shortcut text box.

  5. Click Finish.

Read more...

Retrieving the COM class factory ......failed due to the following error: 80040154.

Retrieving the COM class factory for component with CLSID .....failed due to the following error: 80040154.

This error occuer when you reference unregistered DLL in your solution

Solution: Register your dll using regsvr32.exe utility then add the reference again.

>>> regsvr32 Mydll.dll /u --For unregister
>>> regsvr32 Mydll.dll --For register


How do i find out which dll it is that CLSID {0006F03A-0000-0000-C000-000000000046} refers to ??

to find the dll from CLSID go to the Registry Eidtor.(Run regedit)

In Registry Eidtor on left pan u will get details of all CLSID under:-->

My Computer --> HKEY_LOCAL_MACHIN --> SOFTWARE --> Classes --> CLSID

Read more...

Domain Validation

After sending a mail we need to validate for domain as well as account whether "To" or "From" mail id and domain are valid or not, it can be validate from .NET code using System.Net.Sockets.

Note: Use of sockets requires a trust level above the default "Medium".

Namespace
using System.Net;
using System.Net.Sockets;

C# Code

string email = "recipient@domain.com";

string[] host = email.Split('@');

string hostName = host[1];

Socket socket;

try

{

IPHostEntry entry = Dns.GetHostEntry(hostName);

IPEndPoint endPoint = new IPEndPoint(entry.AddressList[0], 25);

socket = new Socket(endPoint.AddressFamily, SocketType.Stream,

ProtocolType.Tcp);

socket.Connect(endPoint);

}

catch (SocketException ex)

{

// Invalid email.

}


Read more...

IE Developer Toolbar Troubleshooting

Friday, July 3, 2009

The Internet Explorer Developer Toolbar provides several features for exploring and understanding Web pages. These features enable you to:

  • Explore and modify the document object model (DOM) of a Web page.

  • Locate and select specific elements on a Web page through a variety of techniques.

  • Selectively disable Internet Explorer settings.

  • View HTML object class names, ID's, and details such as link paths, tab index values, and access keys.

  • Outline tables, table cells, images, or selected tags.

  • Validate HTML, CSS, WAI, and RSS web feed links.

  • Display image dimensions, file sizes, path information, and alternate (ALT) text.

  • Immediately resize the browser window to a new resolution.

  • Selectively clear the browser cache and saved cookies. Choose from all objects or those associated with a given domain.

  • Display a fully featured design ruler to help accurately align and measure objects on your pages.

  • Find the style rules used to set specific style values on an element.

  • View the formatted and syntax colored source of HTML and CSS.

Some times it’s not work properly.
To work properly we have to do following steps
  • Tools --> Internet options --> Security Tab --> Local Intranet --> Custom Level --> Run ActiveX Control or PlugIn (Administrator Mode)

  • Tools --> Internet Options --> Programs --> Manage add-ons --> IE Developer Toolbar BHO --> Enable

  • Tools --> Internet Options --> Advanced --> Enable third party browser-extensions (requires restart)



Read more...

  © Blogger templates Newspaper by Ourblogtemplates.com 2008

Back to TOP