4

Following code works perfectly in iOS 6.0.1 (using iOS virtual keyboard, I pressed "Go" button on input box)

<html>
    <body>
        <form action="http://stackoverflow.com/" target="_blank">
            <input type="text" />       
        </form>
    </body>
</html>

But when I tried the exact same code on iOS 7.0.3, this does not work at all. No response after I press "Go" button on iOS keyboard.

If I remove [target="_blank"] from form tag, then it works properly.

I have no idea what is the reason for this problem. Does anyone have the same issue?

planetes853
  • 309
  • 1
  • 4
  • 11

3 Answers3

7

Popups are blocked by safari iOS by default.

Disable the block feature by settings -> Safari -> Block Pop-ups.

Grant Zhu
  • 2,988
  • 2
  • 23
  • 28
0

Assuming the HTML is outside of your control, a workaround is to remove the form target property programmatically. Implement the following in your web view delegate:

- (void)webViewDidFinishLoad:(UIWebView *)aWebView
{
        NSString *script = @"for (i=0; i<document.forms.length; i++) { document.forms[i].target = null; }";
        [aWebView stringByEvaluatingJavaScriptFromString:script];
    }
}
jrc
  • 20,354
  • 10
  • 69
  • 64
0

Here is a little jQuery workaround I used to remove the target="_blank" attribute on iOS only, on submit:

$('#searchform').submit(function(e) {
  if(navigator.userAgent.match(/(iPod|iPhone|iPad)/i)) {
    $(this).removeAttr('target');
  }
});

It seems there isn't any better solution as the solution to transit through a temporary a tag doesn't work on iOS 8+.

Community
  • 1
  • 1
vard
  • 4,057
  • 2
  • 26
  • 46