admin管理员组文章数量:1405559
I am developing mobile app(IOS/android) UI with phonegap/cordova 2.1.0. I want to open a link given in href attribute of anchor tag in a new window/page. I tried :
target="_blank"
But it is not working in IOS. Any workaround available?. Thanks
I am developing mobile app(IOS/android) UI with phonegap/cordova 2.1.0. I want to open a link given in href attribute of anchor tag in a new window/page. I tried :
target="_blank"
But it is not working in IOS. Any workaround available?. Thanks
Share Improve this question asked Nov 8, 2012 at 9:16 clintclint 1,9564 gold badges35 silver badges62 bronze badges 3- Where do you expect it to open? If you are in Phonegap, there aren't any new windows/tabs? – Rich Bradshaw Commented Nov 8, 2012 at 9:18
- That should work, according to the [Safari HTML documentation][1]. Could you post your code? [1]: developer.apple./library/safari/#documentation/… – Vidar S. Ramdal Commented Nov 8, 2012 at 9:23
- In phonegap, can i not open another window/tab? – clint Commented Nov 8, 2012 at 10:39
2 Answers
Reset to default 3If you can use JQuery :
<a href="http://link." rel="external">link</a>
Javascript :
$(document).ready(function(){
$('a[rel="external"]').click(function() {
window.open($(this).attr('href'));
return false;
});
});
Sources
don't touch your javascript file, just write on your MainViewController.m file this code, before @end tag. I work with cordova framework like you.
(BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *url = request.URL.absoluteString;
NSString *pathExtension = [[url lastPathComponent] pathExtension];
if([pathExtension isEqualToString:@"pdf"]){
[[UIApplication sharedApplication] openURL:request.URL]; return NO;
} else if([[request.URL host] isEqualToString:@"www.yoururl."]){
[[UIApplication sharedApplication] openURL:request.URL]; return NO;
}
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType]; }
Here you can view two different instructions, all pdf files will be open in a new window, and after on request.URL you need to wirte your url. If you www.yoururl./folder1/folder2 you don't need to write all the urls, because maybe you will have many different url. You just need to write the www.yoururl. from your site.
Hope it helps for you, this works for me. =)
本文标签: javascripttarget quotblankquot not working in IOSStack Overflow
版权声明:本文标题:javascript - target ="_blank" not working in IOS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744311266a2600039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论