0

The question is practically in the title. I am trying to simulate an enter button click on the find a file input (with id "inplaceSearchDiv_WPQ1_lsinput") of SharePoint, after having populated it with a value that I get from the query string. (See code snippet below which I added as a script in the AllItems.aspx view page)

$( window ).on( "load", function() {
    var e = jQuery.Event("keypress");
    e.which = 13; //choose the one you want
    e.keyCode = 13;

    var input = document.getElementById("inplaceSearchDiv_WPQ1_lsinput");

    var textval = getParameterByName("Name");
    input.value = textval;

    //document.getElementById("inplaceSearchDiv_WPQ1_lsimg").click();
    $("#inplaceSearchDiv_WPQ1_lsinput").trigger(e);
})

I also tried the .click() function on the input itself, on the span and search image.

Both the .trigger with the 'e' event and the .click() methods do nothing: practically the code is passed and no click is fired.

The console returns the below errors intermittently:

HTTP 403 - The server understood the request, but is refusing to fulfill it. 
POST - https://outlook.office365.com/owa/

And:

HTTP 401 - DENIED - The requested resource requires user authentication.

These errors appear regardless of the code being included or not. I am mentioning them as I am wondering whether they could be preventing the methods from working.

Does SharePoint block such events? If yes how can I go around it?!

Any ideas?


Update: I noticed that even though the value is being filled in by javascript, I cannot manually submit the input, unless I manually type in the text, remove the javascript work and click enter or click the search button. This may be the reason why I cannot submit it programatically either. Nonetheless, I still would like someone's input about my problem. Perhaps another way of achieving the same thing. Thanks!

0

Think of the security implications if it is possible to do that manual operation programmatically

I could write code that grabs any file from your local system

So it is has nothing to do with the Office365 Server-side

It is the Browser denying access and safe-guarding you.

Why isn't it possible to programmatically trigger the file input selection?

Most browsers prevent submitting files when the input field didn't receive a direct click (or keyboard) event as a security precaution. Some browsers (e.g. Google Chrome) simply prevent the click event, while e.g. Internet Explorer doesn't submit any files that have been selected by a programmatically triggered file input field. Firefox 4 (and later) is so far the only browser with full support for invoking "click"-Events on a completely hidden (display: none) file input field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.