I have enabled collapse sidebar in my customize/user interface. On my Visualforce page, it works fine originally. But since my first element in the page is an inputField of a datetime type, and it auto pops up the datetime picker once re-load, I added the following code to set focus on a hidden elment.
In page:
<input id="hiddenElement" type="hidden" />
In JS:
window.onload = setFocus;
function setFocus() {
document.getElementById("hiddenElement").focus();
}
This works fine but the issue with this is the sidebar suddenly refused to collapse.
I can walkaround this by putting this code into document.ready() - which might be a little bit unstable for setting focus. Or I can use the following code:
if (document.getElementById('sidebarDiv')){
Sidebar.prototype.theSidebar = new Sidebar(document.getElementById('sidebarDiv'), true, false);
}
But I am feeling confused about why setting focus on the hidden element during page loading has caused sidebar collapse stopped working. Any thoughts?