Chrome和--allow文件存取的档案 [英] Chrome and --allow-file-access-from-files

查看:90
本文介绍了Chrome和--allow文件存取的档案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery / AJAX登录页面,在Chrome浏览器以外的所有浏览器完美的作品。看来我已经碰到它覆盖在<一个在Chrome的问题href="http://stackoverflow.com/questions/2541949/problems-with-jquery-getjson-using-local-files-in-chrome">Problems使用本地文件的Chrome浏览器的jQuery的getJSON - 有人说这是一个错误,有人说这是很好的安全性。我说这是令人沮丧的。

我要补充一点的牌子实际上是在工作,那就是打破了AJAXiness。一个解决方案是增加的 - 让文件存取的档案应用于启动环境。很好,但如何解决这对谁使用Chrome网站访问者的问题?

作为一个Chrome浏览器的用户将是具有讽刺意味不得不code,以检查用户提供Chrome和说:使用别的东西。

有没有人对如何可能可以解决此问题code?

任何想法

对于什么是值得的,这里是code:

 $(文件)。就绪(函数()
{
    $(#login_form)。递交(函数()
    {
        //删除所有类中添加消息框类,并开始褪色
        。$(#MSGBOX)removeClass移除()addClass(信息框)文本('检查...')淡入(1000)。
        //检查用户名是否存在或不是从阿贾克斯
        $。员额(/ ajaxsignin.php,{EMAIL:$('#邮件)VAL(),密码:$('#密码)VAL(),请记住:$('#记得)。 VAL(),兰德:的Math.random()},功能(数据)
        {
          如果(data.success)//如果正确的登录细节
          {
////////////////////////////////////////////////// ///////////////////
//如果我把警报()在这里,浏览器只是没有看到它,但其他所有浏览器做
////////////////////////////////////////////////// ////////////////////

                的document.getElementById(MSGBOX)的innerHTML =登录成功。

                。的document.getElementById(topmenutext)style.paddingTop ='的3px';

                的document.getElementById(topmenutext)的innerHTML =错误报告&NBSP;&NBSP;&NBSP;&NBSP; |登出|联系我们|帮助。

                VAR SPATH = window.location.pathname;
                变种S页面= sPath.substring(sPath.lastIndexOf('/')+ 1);

                如果(S页面==register.php|| S页面==的index.php|| S页面==){
                    window.location.href ='menu.php';
                }
                其他{
                    disablePopup();
                }

          }
          否则//如果登录失败
          {
              $(#MSGBOX)。fadeTo(200,0.1,函数()//开始褪色的消息框
            {
              //添加消息,并改变类的箱子,并开始褪色
              $(本)。html的(登录失败 - 也许你需要注册一个帐号)addClass('messageboxerror')fadeTo(900,1)。
            });
          }

        },JSON);
        返回false; //没有张贴的形式物理
    });
    //现在称之为AJAX也从焦点移到
    $(#submitbtn)。点击(函数()
    {
        $(#login_form)触发(提交)。
    });
}); 

解决方案

不要使用该标志。你打开你的计算机或用户机器的攻击。代替运行本地服务器。这就像打开一个shell /终端/命令行并键入

一样简单

  CD路径/到/文件
蟒蛇-m SimpleHTTPServer
 

然后将浏览器指向

 的http://本地主机:8000
 

如果你发现它的速度太慢<一href="http://stackoverflow.com/questions/12905426/faster-alternative-to-pythons-simplehttpserver">consider该解决方案

I have a jquery/AJAX sign in page that works perfectly in all browsers except Chrome. It seems I have bumped into an issue in Chrome which is covered at Problems with jQuery getJSON using local files in Chrome - some say it is a bug, others say it is good security. I say it is frustrating.

I should add that the sign in actually works, it is the AJAXiness that breaks. A solution is to add --allow-file-access-from-files to the startup environment. Fine, but how does this solve the problem for site visitors who use Chrome?

As a Chrome user it would be ironic to have to code to check for users with Chrome and say "use something else".

Does anyone have any idea on how it might be possible to code around this issue?

For what it is worth, here is the code:

$(document).ready(function()
{
    $("#login_form").submit(function()
    {
        //remove all the class add the messagebox classes and start fading
        $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
        //check the username exists or not from ajax
        $.post("/ajaxsignin.php",{email:$('#email').val(), password:$('#password').val(), remember:$('#remember').val(), rand:Math.random()} ,function(data)
        {
          if(data.success) //if correct login detail
          { 
/////////////////////////////////////////////////////////////////////
//  if I put an alert() here, Chrome just doesn't see it but all other browsers do
//////////////////////////////////////////////////////////////////////

                document.getElementById("msgbox").innerHTML='Sign in successful';

                document.getElementById("topmenutext").style.paddingTop='3px';

                document.getElementById("topmenutext").innerHTML="BUG REPORT    |sign out|contact|help";

                var sPath = window.location.pathname;
                var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

                if(sPage == "register.php" || sPage == "index.php" || sPage == ""){
                    window.location.href='menu.php';
                }
                else{
                    disablePopup();
                }

          }
          else //if login failed
          {
              $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
            { 
              //add message and change the class of the box and start fading
              $(this).html('Login failed - perhaps you need to register for an account').addClass('messageboxerror').fadeTo(900,1);
            });     
          }

        },"json");
        return false; //not to post the  form physically
    });
    //now call the ajax also focus move from 
    $("#submitbtn").click(function()
    {
        $("#login_form").trigger('submit');
    });
});

解决方案

Don't use that flag. You're opening your machine or your users machines to attacks. Instead run a local server. It's as easy as opening a shell/terminal/commandline and typing

cd path/to/files
python -m SimpleHTTPServer

Then pointing your browser to

http://localhost:8000

If you find it's too slow consider this solution

这篇关于Chrome和--allow文件存取的档案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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