<form target=“_blank”> not working in iOS 7.0.3

不想你离开。 提交于 2019-12-30 07:02:11

问题


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?


回答1:


Popups are blocked by safari iOS by default.

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




回答2:


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];
    }
}



回答3:


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+.



来源:https://stackoverflow.com/questions/19899553/form-target-blank-not-working-in-ios-7-0-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!