简体   繁体   English

当用户单击fineuploader按钮时,如何重定向他们而不显示文件选择对话框?

[英]When a user clicks the fineuploader button, how can I redirect them instead of showing the file selection dialog?

We are using .net and fineuploader. 我们正在使用.net和fineuploader。 If the users session has timed out and they click the fineuploader button, we need to be able to redirect them to a login page instead of showing them the file selection dialog. 如果用户会话已超时,并且他们单击fineuploader按钮,则我们需要能够将他们重定向到登录页面,而不是向他们显示文件选择对话框。

We have been able to sort-of do it in the "submit" event of fineuploader but the user still sees the file selection dialog before they do our redirect. 我们已经能够在fineuploader的“提交”事件中进行分类,但是用户在执行重定向之前仍会看到文件选择对话框。

$("#fine-uploader").fineUploader().on("submit", function (event, id, name) 
{
  if (noSession){
    cancelUploads();
    window.onbeforeunload = function () { return; }
    location.href = "/login";
  }
}

I did not see any events that fire before the file selection dialog, unless I missed it ( http://docs.fineuploader.com/api/events.html ). 我没有看到任何在文件选择对话框之前触发的事件,除非我错过了它( http://docs.fineuploader.com/api/events.html )。

Is there a way to do something before the file selection dialog is shown? 在显示文件选择对话框之前,有什么方法可以做吗?

you can use prevent default to stop the submit action and run your check. 您可以使用prevent default停止提交操作并运行检查。 Use an else statement to finish the submit if they are logged in. 如果登录,请使用else语句完成提交。

 $("#fine-uploader").fineUploader().on("submit", function (event, id, name) { event.preventDefault(); if (noSession){ cancelUploads(); window.onbeforeunload = function () { return; } location.href = "/login"; } else{ return true; } } 

https://api.jquery.com/event.preventdefault/ https://api.jquery.com/event.preventdefault/

The solution is probably as simple as attaching a click handler to the underlying file input element, preventing the browser's default action on click (which normally shows the file chooser), and then redirect the user to the page of your choice: 该解决方案可能很简单,只需将点击处理程序附加到基础文件输入元素,防止浏览器对点击进行默认操作(通常会显示文件选择器),然后将用户重定向到您选择的页面:

document.querySelector('input[type="file"]')
   .addEventListener('click', function(event) {
      event.preventDefault()
      location.href = "/login"
   })

Add this event handler when you want to redirect, and remove it when you don't. 当您要重定向时,请添加此事件处理程序;否则,请删除它。 Or, you can add it after the uploader has been created, and add some logic to the click handler function that only prevents the default action and redirects if the user must re-login. 或者,您可以在创建上传器后添加它,并向单击处理程序函数添加一些逻辑,该逻辑仅阻止默认操作并在用户必须重新登录时重定向。

Warning: I have not tested this cross-browser (only Chrome). 警告:我尚未测试此跨浏览器(仅适用于Chrome)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JQuery-ui对话框:当用户点击关闭按钮时,如何防止默认操作? - JQuery-ui Dialog: How can I prevent default action when the user clicks on close button? 当用户单击“返回”按钮时,如何关闭SimpleModal对话框? - How can I close a SimpleModal dialog when the user clicks the Back button? 当用户单击按钮时,如何使用textarea弹出窗口? - How can I have a textarea popup when the user clicks a button? 用户单击按钮时如何执行JavaScript - How can i execute a javascript when a user clicks a button 用户单击按钮时如何存储类名称,以便下次访问时可以将其用作默认名称? - How can I store a class name when a user clicks on a button so it can be used as a default on next visit? 在用户单击javascript / jquery中的按钮之前,如何防止元素加载? - How can I prevent an element to load until such time when the user clicks a button in javascript/jquery? 当用户单击jQueryUI单选按钮时,如何停止浏览器视口移至页面顶部? - How can I stop the browser viewport moving to the top of the page when the user clicks on a jQueryUI radio button? 当用户单击按钮时,如何创建空格线(如 br)? - How can I create a space line (like a br) when user clicks on button? 当用户单击按钮时,如何解构只有数据的数组? - how can i destructure an array that only has data when the user clicks the button? 当用户单击按钮时如何防止作弊 - How do I prevent cheating when user clicks a button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM