Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

Javascript: 

 

 

The error message

File chooser dialog can only be shown with a user activation

Displayed when you try to open a file dialog in Javascript by clicking.

Open file dialog via javascript click()

 

 

Here is the javascript code

 

function editor_open_FileDialog() {

    //------< editor_open_FileDialog() >------

    editor_Remove_all_ImageResize_Divs();

 

    Upload_Files_Target = "Files";

    var input_Files = document.getElementById("files_input_field");

    input_Files.click();

    //------</ editor_open_FileDialog() >------

}

 

error message

 

The HTML element that triggers the event is a link a without href with a a.onclick() event

<a title="Insert Images, Files, Videos" class="fab_Button fab_Button_edit" onclick="editor_open_FileDialog();">

 <span class="fab_Icon">+📎</span>

</a>

 

 

Hidden on the website is a file upload field, which should be addressed.

<form method="post" enctype="multipart/form-data">

<input type="file" id="files_input_field" name="files" multiple style="visibility:hidden;height:0px;width:0px;" onchange="upload_Files_onChanged();" />

</form>

 

solution 1:

solved: The error message File chooser dialog can only be shown with a user activation Displayed when you try to open a file dialog in Javascript by clicking.

 

solution 2:

You have to change the HTML element from a to button.

The .click() then no longer needs to be executed.

<button title="Insert Images, Files, Videos" class="fab_Button fab_Button_edit" onclick="editor_open_FileDialog();">

                <span class="fab_Icon">+📎</span>

</button>

 

 

functioned:

Open file dialog via button

After changing the HtmlElement to <button>, the file dialog opens as expected

Mobile

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de