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
Add a ment  | 

2 Answers 2

Reset to default 3

If 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