1

I am trying to open input file dialog after clicking on link. I made a script with jquery. But I also want to avoid opening this dialog after clicking on input file:

            $('#link').click(function(event) {
                event.preventDefault();
                $('#id_default_image').click();
            });
            $('.file_input').click(function(event) {
                event.preventDefault();
            });

Now when I click on link or input file dialog does not show. Can I check if user clicks on link or on input and show dialog or not?

1 Answer 1

4

You can use global flag for this, and raise it when clicking the link.

Code will now be:

$('#link').click(function(event) {
    event.preventDefault();
    window["link_clicked"] = true;
    $('#id_default_image').click();
    window["link_clicked"] = false;     
});

And to check the flag:

$('.file_input').click(function(event) {
    if (window["link_clicked"]) {
        alert("you clicked the link");
    }
    //event.preventDefault();
});

Live test case: http://jsfiddle.net/trG5D/1/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.