Yesterday modified the EPG page above the set-top box, encountered a small problem. Users need to buy the game pop-up Purchase confirmation dialog box, the default focus of the dialog box must stay on the "Cancel" button. Very simple requirements, the focus () method of using JavaScript can be implemented. A simple code example is as follows:
document.getElementById ("Cancel"). Focus ()
But the hard drive is that the set-top box is really a big pit. To be compatible with all existing set-top box models, 8 set-top boxes need to be fitted. And then there's the problem! A ZTE B600 set-top box is completely unable to focus on the cancellation button. The following is my solution:
First verify that the set-top box supports the getElementById () method and that the element with the id "Cancel" was successfully obtained: The test method is simple, and a <p id= "test" >test</p> is written directly. Then get the element with the ID "test" in the same place and do a simple operation document.getElementById ("test"). Innerhtml= "Hello"
Finally, "Try...catch (E) ..." was used to capture the cause of "focus ()" failure
Try () {
<span style= "White-space:pre" > </span>document.getelementbyid ("Cancel"). Focus ()
} catch (e) {
<span style= "White-space:pre" > </span>alert (e.name + ":" + e.what ());
}
But it's just weird! The results of both of these steps indicate that the set-top box supports focus () and getElementById (), but that it is not possible to set focused to a pop-up dialog box.
After tossing one hours, the last big boss appeared, simply said a word to solve the problem! It is possible to actively invoke Flur () to cancel the original focus!
document.getElementById ("Purchase"). Flur ()
Then it solves the problem. Have to feel! In the process of solving this problem, their own thinking is actually quite correct, but the knowledge is clearly not enough. The gap between general programmers and senior programmers in addition to solving the problem of thinking, there are experience and knowledge gap!