Saturday, October 8, 2011

Making window.find method move to the start of the webpage firefox javascript

To make the window.find method move to the starting of the webpage incase when user clicked clear or he is trying to search for another word.

You need to select a word in the starting of the Page and using that word you need to perform window.find method which makes the cursor to move to the start of the webpage

For example in my case i select a word "linux" which lies in the first line of my webpage

You need to do like this:

sel.removeAllRanges(); // To remove any of the selections previously available in the webpage

found=window.find("linux,"false,false); // To select the word in the first line

sel=window.getSelection(); // To select the word to sel

range=sel.getRangeAt(0); // to add the selection to the range

if (sel.RangeCount > 0 ) sel.removeAllRanges(); // To remove the selection made by "linux" word

sel.addRange(range); // To add the selection to sel using addRange

This will do the trick moving to the first part of the webpage.

No comments:

Post a Comment