how to focus to a div both in firefox and IE
2007-07-24 12:38
501 查看
The following code work well in IE to focus to a div:
document.getElementById("div1").focus();
However, it doesn't work in firefox. You will not see any action taken after the line is executed. To workaround the issue, you can use the following code:
function getOffsetTop(el)
window.scrollTo(0,getOffsetTop(e));
getOffsetTop method is used to get the accurate top pixel of any element.
Here, window.scrollTo has two parameters. The first one represents offsetX and the second one represents offsetY. Here we only use the second parameter to scroll to the top border of the target control.
document.getElementById("div1").focus();
However, it doesn't work in firefox. You will not see any action taken after the line is executed. To workaround the issue, you can use the following code:
function getOffsetTop(el)
window.scrollTo(0,getOffsetTop(e));
getOffsetTop method is used to get the accurate top pixel of any element.
Here, window.scrollTo has two parameters. The first one represents offsetX and the second one represents offsetY. Here we only use the second parameter to scroll to the top border of the target control.
相关文章推荐
- How to detect Safari, Chrome, IE, Firefox and Opera browser?
- How to get multiple select value both in javascript and php
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- User javascript to catch ctrl in IE and Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- How to use *args and **kwargs in Python
- R Markdown: How to format tables and figures in .docx files
- How to Update to Metasploit 4 and use Autopwn in Backtrack 5
- How to thanks company and family for supporting in long career
- Iframe自动适应宽度和高度(both IE and Firefox are ok)
- How to compile and run a simple java file in jenkins on Windows
- How to open Firefox and chrome from command line
- How to use $http and $resource in Angular JS
- How to read and write JSON files in Java(Gson)
- how-to-use-ps-kill-and-nice-to-manage-processes-in-linux
- How to get URL and QueryString value in an ASP.NET page
- How to use *args and **kwargs in Python