ios - Force iOS 应用程序在 safari 中打开外部链接

标签 ios cordova jquery-mobile

我有一个 iOS 应用程序,是我使用 PhoneGap 和 JQuery mobile 制作的。该应用程序有一些我想在移动 safari 中打开的外部链接,但截至目前,它们只是在应用程序 View 中打开。链接是这样写的:

<a rel="external" href="wwww.example.com">Click Here</a>

我阅读了 JQuery 移动文档,它指出添加 rel="external" 可以解决这个问题,但显然不是。有任何想法吗?请记住,这是一个基于 HTML 的应用程序。

最佳答案

最终能够通过导航到 MainviewController.m 并查找其中提到 webView 的部分(如其他帖子中所述)然后将其更改为此

/* Comment out the block below to over-ride */

/*

- (void) webViewDidStartLoad:(UIWebView*)theWebView
{
    return [super webViewDidStartLoad:theWebView];
}

- (void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
    return [super webView:theWebView didFailLoadWithError:error];
}

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
*/

为此

/**

 * Start Loading Request

 * This is where most of the magic happens... We take the request(s) and process the response.

 * From here we can re direct links and other protocalls to different internal methods.

 */

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

{

    NSURL *url = [request URL];

    // add any other schemes you want to support, or perform additional

    // tests on the url before deciding what to do -jm

    if( [[url scheme] isEqualToString:@"http"] ||

       [[url scheme] isEqualToString:@"https"])

    {

        [[UIApplication sharedApplication] openURL:url];

        return NO;

    }

    else

    {

        return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];

    }



}

我没有使用 Objective-C 的经验,所以我不得不尝试这个,所以我很高兴我让它工作了。

关于ios - Force iOS 应用程序在 safari 中打开外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15138721/

相关文章:

iphone - iOS 上 PhoneGap 2.0 的应用内购买 (IAP) 插件?

html - 如何在 jQuery Mobile 中更改面板图像和颜色主题

iphone - iOS 邮件客户端中的间歇性图像链接行为

ios - 如何动态更改 UITableView 中单元格的高度?

android - 有没有办法在 Android/iOS 上的 PhoneGap 中实现视频流?

angularjs - Ionic - 从使用 cordova 插件媒体录制的音频中获取文件

iphone - iPhone四方应用中的TabBar

cordova - iOS 13 beta WebKit 中断了对 cookie 的支持

android - jQuery 移动文本字段不会失去焦点

jquery - 单击按钮本身后如何更改按钮颜色?