Answer the question
In order to leave comments, you need to log in
try-catch IE8
Hello everyone.
I'll tell you a story. It is necessary to open a file selection dialog without clicking the mouse from the side of the user. But browsers block such actions by issuing warnings, because according to their security policy, the file selection action must be initiated by the user. Well, I'm an honest person and I'm ready to ask the user to press enter, BUT: IE8 does not allow focusing on an element of the file type. At the same time, the same IE8 allows you to open a window on a program click without any problems, hence the code was born:
But for some reason, the donkey gives an error in the console, while not processing the catch. How to solve the problem? I don’t want to check different versions for IE, I’m interested in the ideological side of the issue, there must be a civilized method to check whether the method is supported by the object in the current browser. Tried like this
try {
gbid('file').focus(); //тем кто дает делать фокус
} catch (e) {
gbid('file').click(); //остальным кликаем
}
javascript:alert('focus' in document.getElementById('file')); //true
Answer the question
In order to leave comments, you need to log in
You can just do for everyone at once
gbid('file').click();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question