文件上传控件在Facebook应用内浏览器中不起作用 [英] File upload control not working in Facebook In-App Browser

查看:188
本文介绍了文件上传控件在Facebook应用内浏览器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个移动的html Facebook应用程序,可以控制上传文件(一个简单的输入文件)。
当我在浏览器中打开应用程序时,我可以正常上传这个apps.facebook.com/myapp。
但是一旦我通过本地的Facebook应用程序,并将我的应用程序加载到新的FB的内部浏览器中,则上传控件不起作用。




  • 这是预期的行为吗?

  • 如果是这样的话如何解决?

  • 我可以强制应用程式在Chrome浏览器等外部浏览器中开启吗?



谢谢。

解决方案

我们已经通过在输入元素上添加Multiple属性来解决这个问题。它似乎是Facebook浏览器中的一个错误。



这将修复它为iOS,但我们有一些报告,它在Android中不工作。它还添加了一个检查,看看他们是否上传了多个文件(因为这可能不是意图,而是元素允许的)。我希望它有帮助。

  if(navigator.userAgent.match(/ FB /)){
$(' #myinput ')ATTR(' 多个,TRUE);
$('#myinput')。change(function(){
if($('#myinput')[0] .files.length> 1){
// user尝试上传超过1
$('#myinput')。value ='';
alert(对不起,只允许1个文件);
}
} );
}


I have a mobile html Facebook app which has a control to upload files (a simple input file). I can upload fine when I open the app in a browser like this apps.facebook.com/myapp. But once I go through the native Facebook app and load my app in the new FB's internal browser, the upload control doesn't work. It's there on the page but does nothing.

  • Is this an expected behaviour?
  • If so, how do I get around it?
  • Can I force an app to open in an external browser like Chrome?

Thanks.

解决方案

We have fixed this problem by adding a "Multiple" attribute on the input element. It appears to be a bug in the Facebook browser.

This fixes it for iOS, but we have had some reports of it not working still in Android. It also adds a check to see if they uploaded more than one file (since that may not be intended, but is allowed by the element). I hope it helps.

if (navigator.userAgent.match(/FB/)) {
    $('#myinput').attr('multiple',true);
    $('#myinput').change(function(){
        if ($('#myinput')[0].files.length > 1) {
            //user trying to upload more than 1
            $('#myinput').value = '';
            alert("Sorry, only 1 file is allowed");
        }
    });
}

这篇关于文件上传控件在Facebook应用内浏览器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆