P
P
Prescott2011-10-25 23:38:42
HTML
Prescott, 2011-10-25 23:38:42

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

1 answer(s)
O
oraz_ra, 2011-10-26
@oraz_ra

You can just do for everyone at once

gbid('file').click();

Checked only in IE9 (including IE8 "mode") and FF7
The problem is different: FF shows a strip at the top with the inscription "Firefox prevented this site from opening pop-up window" and offers to climb into the options. Perhaps you have already disabled this option, but half of the users have not done this and are unlikely to do so.
In IE, most likely, the same warning will also come out, it's just that this garbage seems to be disabled for me already.
In general, whatever one may say, but browsers consider such gestures as hacks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question