Yesterday when I modified the EPG page on the set-top box, I encountered a small problem. When users purchase a game, a purchase confirmation dialog box needs to pop up. The default focus of the dialog box must stay on the "Cancel" button. A very simple requirement can be achieved using JavaScript's focus() method. A simple code example is as follows:
document.getElementById("cancel").focus()
But the sad thing is that the set-top box is really a big pit. Since it needs to be compatible with all existing set-top box models, 8 sets-top boxes need to be adapted. Then something went wrong! A ZTE B600 set-top box is completely unable to set the focus to the cancel button. The following is my solution:
First confirm whether the set-top box supports the getElementById() method and whether the element with the ID "cancel" has been successfully obtained: the test method is very simple, just write another
test
Finally, "try...catch(e)..." was used to capture the reason why "focus()" failedtry(){ <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 the above two steps show that the set-top box supports focus() and getElementById(), but the focus cannot be set to the pop-up dialog box.
After struggling for more than an hour, the big BOSS finally appeared and solved the problem with just one sentence! It is possible to actively call flur() to cancel the original focus!
document.getElementById("purchase").flur()
Then the problem is solved. I have to appreciate it! In the process of solving this problem, my idea was actually quite correct, but my knowledge was obviously not enough. The gap between ordinary programmers and senior programmers is not only in terms of ideas for solving problems, but also in experience and knowledge!