Skip Navigation LinksHome > Blog > 2008

2008

Javascript: Exception Details

Exceptions do occur in any programming language, and knowing the type and details of the exception can be very crucial in debugging and determining a solution to the cause. I recently ran  into a problem with one of my javascript functions and could not figure out why it was occurring. Little did I know that Javascript also provides exception information in the try, catch block. Here goes: try

How To: Javascript Namespacing

Creating namespaces for javascript on web applications is a very uncommon approach. However, in a world where the possiblity of clashes between variable and function names is very high, especially among scripts from different sources, it becomes important to understand this neat and elegant concept by Dustin Diaz.Basically the steps that make this possible are as follows:Create the Namespace Object

Script to Delete Temporary Internet Files

This script will populate %%B with the usernames held within the 'c:\Documents and Settings' directory.  The DO statement deletes all users temporary internet folder contents.FOR /D %%B IN ("c:\Documents and Settings\*") DO del "%%B\Local Settings\Temporary Internet Files\*.*"  /s /q /f Unlike the temporary Internet files, there isn't an obvious way to limit the size of

How To: Set the filename for a handler

If you create a handler that allows your users to download/view files. When they save the file the browser attempts to save with the filename and extension of the handler.Assuming the name of your handler was "Image.ashx" and in your handler you send an image (maybe resized) to the client. If the user attempts to save that image, it will be saved as "Image.ashx", unless you do one

Javascript: Passing 'this' to inline function

Create a new variable within the parent function:var me = this;use 'me' in new functionExample:  function parentFunction() { this.message = 'Hello World!'; var me = this; var childFunction = function() {   alert(me.message); }  childFunction(); }

Javascript: Function.Call()

Allows you to call (execute) a method of another object in the context of a different object (the calling object). var result = fun.call(thisArg[, arg1[, arg2[, ...]]]); You can assign a different this object when calling an existing function. this refers to the current object, the calling object. With call, you can write a method once and then inherit it in another object, without having to rewrite

Javascript: Function.Apply()

Allows you to apply a method of another object in the context of a different object (the calling object). var result = function.apply(thisArg[, argsArray]);You can assign a different this object when calling an existing function. this refers to the current object, the calling object. With apply, you can write a method once and then inherit it in another object, without having to rewrite the method

Javascript: Class/object property

Just use: this.Property = value;

HexToString and StringToHex

At the moment I am researching on how to convert a regular string to HEX and back. You may wonder why? I gues I'll explain later.EDIT:I have come up with some basic yet incomplete functions to achieve this: 

Javascript "setAttribute()"

I just found out how to modify DOM elements using: element.setAttribute(name, value); Adds a new attribute or changes the value of an existing attribute on the specified element.  name is the name of the attribute as a string. value is the desired new value of the attribute. If the specified attribute already exists, then the value of that attribute is changed to the value passed to this function. If it does not exist, then the attribute is created.

Javascript: Change the OnClick function

After battling with this for days, I finally figured out how to change the OnClick function for an a HTML anchor tag. This method is compatible with browsers as well as IE.a.onclick = new Function() {}

How To: Embed JS and CSS Resources

One of the greatest difficulties when developing common web controls (either server or user controls) that we've come across in our development group is how to deal with client-side scripts and images. In ASP.NET 20 you can just embed your resources in the appropriate assemblies and reference them without having to worry about configuration or deployment issues. To make the JS/CSS file or image

How To: Load Assemblies in an Application Domain

Creating a new application domain and launching an assembly within that domain is as simple as creating an instance of the System.AppDomain class with a friendly name, and then calling the ExecuteAssembly method, as the following code demonstrates:' VBDim d As AppDomain = AppDomain.CreateDomain("NewDomain")d.ExecuteAssembly("Assembly.exe")Excerpt from MSDN: There are several ways

How To: match using backreferences

Backreferencing uses named groups to allow you to search for other instances of characters that match a wildcard. Backreferences provide a convenient way to find repeating groups of characters. They can be thought of as a shorthand instruction to match the same string again.As the name implies, a regex backreference refers to a substring previously encountered in the target text. Backreferences are