Friday, August 27, 2010

Anchor TAG : to anchor any location within a page



Suppose you have button on click you need to anchor  on bottom of page.
The function that you going to call on click is newoffice();

Solutions:
//------------------------------

1. write the following code on the newoffice function.

 function NewOffice()
{   window.location = window.location + "#controlId";}
     // controlId is the name of control, place this control to
        location that you need page to anchor
2. create a label or any control with visibility = hidden , whose id =”controlId”
   Eg.

<asp:Label id="myNew" visiblity="hidden" text=""> </asp:Label>

//------------------------------



No need to make function
//------------------------------

Source (where event will take place like click):
       <a href="#target">Highlighted Text</a>

Target (the place where you want to anchor page):
       <a name="target">Destination</a>

//------------------------------



//------------------------------


Call this function onclick :
                    GotoETag('ench_officehead');

Definition:
function GotoETag(etagname)
{
    var currentHref = window.location.href;
    window.location.href = currentHref.substr(0, currentHref.lastIndexOf("#")) + "#"+etagname;
    return true;
}
If you have requirement to fire two function on single click,
Nest the two function is alos a good option.