Search code examples
iosiphoneiframemobile-safarip3p

Submit a form embedded in an iFrame does not work in iOS 7


In a website with mydomain.tld, an iFrame containing a form that is hosted on otherdomain.tld is embedded. Both sites are non-SSL running on port 80.

Now, this form won't submit on iPhone 5 running on iOS 7. I can reproduce it in the iOS-Simulator when choosing "iPhone Retina (4-inch 64-bit)" (doesn't happen with "4-inch" only).

The submit event is triggered (at least if I catch it via JavaScript) but no request is made according to the developer tools.

If I open the iFrame source directly, the form will submit.

I had a similar problem with Internet Explorer and learned about P3P and could solve the problems sending a special P3P header:

P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"

But for the problem mentioned with Safari this doesn't seem to be the problem.

Are there any known restrictions regarding Safari and forms in iFrames?


Solution

  • As I've found out, the problem was related to using cookies in iFrames which triggered the Spamshield of the form in the iFrame to block the form submission.

    Since it's an opt-in form, I deactivated the Spamshield, but I've found a solution (which I didn't test) that should make cookies work by a submit to a hidden form that is triggered on loading the iFrame content.

    <script>   window.setTimeout(function() {
    if (document.cookie.indexOf('test_cookie=1') < 0) {
      var      
        name = 'test_cookie',
        div = document.getElementById(name),
        iframe = document.createElement('iframe'),
        form = document.createElement('form');
    
      iframe.name = name;
      iframe.src = 'javascript:false';
      div.appendChild(iframe);
    
      form.action = location.toString();
      form.method = 'POST';
      form.target = name;
      div.appendChild(form);
    
      form.submit();
    }   }, 10); </script>
    

    Source: https://gist.github.com/daaku/586182