JS form submit “This page cannot be loaded using C

2019-09-01 20:19发布

问题:

I have a form on a simple page. When submitting it passes data of the "first name, last name, email" to the "real" join form of my customer and enables the user to continue to fill in the form with the data.

When my customer is running it on some android mobile phones he get this error:

This page cannot be loaded using Chrome Data Saver. Try reloading the page.

Debug info: POST CISmtuKa5MwCFUIEYgodMxIGmQ==

On every mobile phone I tested it - it works fine. The customer tested it on 2 different mobile phones and he (only) got these errors. This doesn't happen on desktops as far as I tested it. I tested it on some different browsers on my android too and it works fine.

This is the form I have:

<form id="preregistrationForm" action="" onsubmit="return get_action();" method="post">

    <div>
        <input type="text" name="FirstName" id="FirstName" placeholder="First Name">                            
    </div>

    <div>
        <input type="text" name="LastName" id="LastName" placeholder="Last Name">
    </div>

    <div>
        <input type="text" name="EMail" maxlength="50" id="EMail" placeholder="Email">                            
    </div>

    <input type="hidden" id="maleGengler" class="genderRadio" name="Gendler" value="M" checked="">
    <input type="hidden" id="femaleGengler" class="genderRadio" name="Gendler" value="F">

    <select name="birthDateMonth" id="birthDateMonth" style="display: none;">
    </select>
    <select name="birthDateDay" id="birthDateDay" style="display: none;">
    </select>
    <select name="birthDateYear" id="birthDateYear" style="display: none;">
    </select>

    <input type="hidden" name="btag" id="btag" value="">
    <input type="hidden" name="affid" id="affid" value="">

    <button class="join-sub" onclick="chgAction()"></button>

</form>

And this is the JS code. The last function chgAction() is the one that needs to be interesting. I just pasted all the code, just incase =] :

var Adp = {

    getBtag: function() {
        // split url and retrieve btag
        var aPath = window.location.href.split("?");
        var sbtag = aPath[aPath.length - 1];
        return sbtag;
    },

    persistAffiliateData: function() {
        // get the affiliate data from the url
        var bTag = Adp.getBtag();
        if (!bTag) { return false; }

        // get all the links on the page
        var aLinks = document.getElementsByTagName("a");
        if (!aLinks) { return false; }

        // add the affiliate data to the links to exampleurl
        for (var i = 0; i < aLinks.length; i++) {
            if (aLinks[i].href.indexOf("exampleurl") > 0 || aLinks[i].href.indexOf("localhost") > 0) {
                aLinks[i].href = aLinks[i].href + "?&" + bTag;
            }
        }
    }
};

function addLoadEvent(func){
    // appends unlimited functions to the onload event 
    var oldonload = window.onload;
    if(typeof window.onload != 'function'){
        window.onload = func;
    }else{
        window.onload = function(){
            oldonload();
            func();
        }
    }
}

addLoadEvent(Adp.persistAffiliateData);

/*Function used of the pre-signup form of the sites*/
function getQueryStringByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}



function chgAction()
{ 
    var btag = getQueryStringByName("btag"); 
    var affid = getQueryStringByName("affid"); 
        var isIncomeAccess = "false";
    if (btag !="" && affid != "")
    {
        isIncomeAccess = "true";
    $("#btag")[0].value=btag;
    $("#affid")[0].value=affid;
    }
    var feObj=$("#femaleGengler")[0];
    if (feObj.checked){
    Gendler="F";
    }else
    {Gendler="M";}

    var _action = "//www.exampleurl.com/preregistration?Gendler="+Gendler+"&FirstName="+$("#FirstName")[0].value+"&LastName="+$("#LastName")[0].value+"&EMail="+$("#EMail")[0].value+"&birthDateMonth="+$("#birthDateMonth")[0].value+"&birthDateDay="+$("#birthDateDay")[0].value+"&birthDateYear="+$("#birthDateYear")[0].value;
    if(isIncomeAccess=="true")
         _action  += "&btag="+btag+"&affid="+affid;
    document.getElementById("preregistrationForm").action = _action;
    document.getElementById("preregistrationForm").submit();
    document.getElementById("preregistrationForm").action = _action;
}

回答1:

I'm the tech lead on the Chrome Data Saver team. This will occur if the user has the Data Saver feature enabled in Chrome (either desktop or mobile) and our proxy can't talk to the backend server that you are doing the POST to. Is this because the server is behind an intranet?

The short-term workaround is to ask people to turn off Data Saver, but that is not ideal -- we should be able to avoid this being a problem for you in the first place. Any details you can provide on the site would be helpful. If you prefer to email directly I am mdw at mdw dot la. Thanks.