RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • About
  •  

    Rolling back from Firefox 3 to Firefox 2

    June 18th, 2008

    1

    Firefox 3 was released today. I too downloaded and installed. But when I ran the new Firefox, I was disappointed because webmaster essential plugins such as Firebug and Web Developer Toolbar did not pass the compatibility check neither there were any new compatible versions available. I know this ain’t Firefox’s fault but I can’t live without those plugins. So here is how i rolled back to Firefox 2.0.0.0.14

    1. Download Firefox 2.0.0.14 from OldApps.com122 but don’t install it immediately.
    2. Uninstall Firefox 3 by going to Control panel>Add/Remove programs. If you don’t uninstall it, the newly installed 2.0.0.14 crashes on launching. This seems like a bug.
    3. Now install 2.0.0.14 and it will work like a charm

    NewVirusRemoval.vbs: USB drive not opening? Here is a workaround

    June 17th, 2008

    If you have been infected with this malware “newvirusremoval.vbs” and it has made its way to your USB drive, it may probably give you an error message saying that “Windows Script Host: Can not find script file X:\newvirusremoval.vbs” and will not let you open the USB drive.

    Simple workround is to type the full path into the windows explorer address bar eg: H:\projects\rohan\.

    I had ‘AVG 8 free’ detect this virus but when asked to heal, it told me to upgrade(I know it ain’t good).

    Note: This is just a woraround and does not heal the infection. Its meant only so that your important files do not get locked up. but remember to heal it later.


    Export Bluebottle.com contact list as CSV

    June 13th, 2008

    Bluebottle.com has decided to stop its freemail service June 20 2008 onwards. This was notified to its freemail users only on June 12 2008, leaving them with barely 8 days if they decided not to upgrade. I too am a freemail user. Am I not sure if I will be able to pay them, not because that its too expensive, but because I don’t have a credit card or a debit card. While I am looking if any of friends has it, but in case I don’t find one, I am exporting my contact list as CSV. Bluebottle does not offer any such option, hence I decided to write a script to ease other distressed users.

    If you want to export your contact list in CSV, please use this tool.


    Auto-logout after some time of inactivity with JavaScript

    June 12th, 2008

    Logging out a user after a particular period of inactivity is a good measure(!?) to ensure that the user is there attending the screen and has not left it unattended. I have commonly seen such implementation while reading my webmails. If there is no activity for 5 minutes, I am auto-logged out because the system assumes that I may not be sitting in front of the PC and hence somebody else may get an opportunity to read my emails.

    Logic:

    You can achieve the same inactivity-induced auto-logout by using javascript. The logic is:

    1. Start an timer as soon as the page loads.
    2. On every activity, reset the timer. Since there is no in-built javascript function to reset the timer, to reset the timer, we have to first clear the previous timer and then immediately implement another timer.
    3. If the timer runs out due to inactivity, redirect the user to your logout page

    The JavaScript:

    [-]View Code JAVASCRIPT
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    <script type="text/javascript">
    function set_interval()
    {
    //the interval 'timer' is set as soon as the page loads
    timer=setInterval("auto_logout()",10000);
    // the figure '10000' above indicates how many milliseconds the timer be set to.
    //Eg: to set it to 5 mins, calculate 5min= 5x60=300 sec = 300,000 millisec. So set it to 3000000
    }
     
    function reset_interval()
    {
    //resets the timer. The timer is reset on each of the below events:
    // 1. mousemove   2. mouseclick   3. key press 4. scroliing
    //first step: clear the existing timer
    clearInterval(timer);
    //second step: implement the timer again
    timer=setInterval("auto_logout()",10000);
    ..completed the reset of the timer
    }
     
    function auto_logout()
    {
    //this function will redirect the user to the logout script
    window.location="your_logout_script_location_here";
    }
    </script>

    The HTML tags

    The body tag should listen to these 3 events to record activity.

    1. Mouse move
    2. Mouse click
    3. Key press
    4. Scrolling

    The markup would thus be

    1
    2
    3
    4
    
    .
    <body onmousemove="reset_interval()" onclick="reset_interval()" onkeypress="reset_interval()" onscroll="reset_interval()">
    .
    .

    Thats it. Your inactivity-induced auto-logout is ready to be implemented!


    Moving table rows up and down with JavaScript

    June 10th, 2008

    While there a lot complicated javascript code snippets to move table rows up and down, this one is very easy provided you can use the below functions fluently.

    1. IF….ELSE conditional statements
    2. User made javascript function with arguments
    3. HTML table row Index property
    4. document.getElementsByTagName()
    5. cloneNode()
    6. replaceChild()

    If you prefer not to use DOM manupulation, then you can try the simpler method given at the end of this post, but please read it limitation.

    Lets start:

    The table layout and markup:

    The table layout:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    
    <table border=1>
      <tr>
           <td>1. </td>
           <td> Description of item 1 </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’up’)>Move up</a> </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’down’)>Move down</a> </td>
      </tr>
      <tr>
           <td>2. </td>
           <td> Description of item 2 </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’up’)>Move up</a> </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’down’)>Move down</a> </td>
      </tr>
      <tr>
           <td>3. </td>
           <td> Description of item 3 </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’up’)>Move up</a> </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’down’)>Move down</a> </td>
      </tr>
      <tr>
           <td>4. </td>
           <td> Description of item 4 </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’up’)>Move up</a> </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’down’)>Move down</a> </td>
      </tr>
      <tr>
           <td>5. </td>
           <td> Description of item 5 </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’up’)>Move up</a> </td>
           <td> <a href=”javascript: void(0)onclick=”move(this,’down’)>Move down</a> </td>
      </tr>
    </table>

    The user-made javascript function:

    We use the user-made function named move(), with two arguments. The first argument is supposed to help us recognize the row which we want to move either up or down. The second arguments is supposed to let us know the direction in which the row should be moved: Either up or down.

    The javascript code:

    The logic of the code is explained as comments. So please read them:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    
    function move(elem,direction)
    {
    //since we have to deal with two rows: the row that should be moved and the other row which is adjacent to it, we have to first establish references to each of them. We establish these references using the rowIndex property.
     
    //lets get the row index on the row that is to be moved(the one on which the user clicked)
    //	  a	td		tr  
    clickedRowIndex=elem.parentNode.parentNode.rowIndex;
     
    //This row could either be the first row or the last row or some inbetween row.
    //The first row cannot be moved upwards. So if the user tries to move the first row upwards, we will have to tell him that it can’t be done.
    if(clickedRowIndex ==”0&& direction==”up”)
    	{
    alert(This is the uppermost row and connot be moved upwards”);
    return false;
    }
     
    //Similarly, if the user wants to move the last row downwards, we again tell him that it isn’t possible
    //For this, this we will have to first find how many rows are there in the table, then compare if the rowIndex(rindex) is same as that of last row
    maxrindex= (elem.parentNode.parentNode.parentNode.getElementsByTagName(“tr”).length)-1;
    if(clickedRowIndex ==maxrindex && direction==”down”)
    	{
    alert(This is the bottommost row and cannot be moved downwards.”);
    return false;
    }
     
    //for easy reference to the parent elements, lets setup reference to the parent HTML table.(table tag)
    parentTable=elem.parentNode.parentNode.parentNode;
     
    //establish reference to the row which is supposed to be moved(the one on which the user clicked)
    clickedrow=parentTable.getElementsByTagName(“tr”)[clickedRowIndex];
     
    //establish reference to adjacent row.
    //If the direction is ‘up’, the adjacent row’s rowIndex will be 1 less that that of ‘clickedrow’
    // If the direction is ‘down’, the adjacent row’s rowIndex will be 1 more that that of ‘clickedrow’
     
    if(direction==”up”)
    {
    adjacentRowIndex= clickedRowIndex –1;
    }
     
    if(direction==”down”)
    {
    adjacentRowIndex= clickedRowIndex +1;
    }
     
    adjacentrow= parentTable.getElementsByTagName(“tr”)[adjacentRowIndex];
     
    //Once that we have established references to both the rows that should change their position, we should clone each of them
    clickedrow_clone=clickedrow.cloneNode(true);
    adjacentrow_clone=clickedrow.cloneNode(true);
    //both the cloned nodes remain ‘invisible’ to the user.
     
    //now replace the nodes. 
     
    //The below replaceChild() function will replace the adjacentrow with ‘clone of the clicked row’ and then remove the clone on the clicked row.
    adjacentrow=parentTable.replaceChild(clickedrow_cloned,adjacentrow);
     
    //similar replacement as above
    clickedrow=parentTable.replaceChild(adjacentrow_cloned,clickedrow);
     
    // the clones of two rows that we made above were automatically removed by the replaceChild() function.
    }

    Alternate much easier way, but with limitations

    If you are not comfortable with DOM, or simplt wouldn’t like to use it, you can also move rows by swapping their innerHTML. However, its limitation is that it cannot preserve the state of input elements. Eg: If you check a checkbox and then move it upwards, the checkbox would be checked while moving it.