久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

打開(kāi)目標(biāo)=“_blank";Safari 中 UIWebView 之外的鏈

Open target=quot;_blankquot; links outside of UIWebView in Safari(打開(kāi)目標(biāo)=“_blank;Safari 中 UIWebView 之外的鏈接)
本文介紹了打開(kāi)目標(biāo)=“_blank";Safari 中 UIWebView 之外的鏈接的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

在我的 iOS 應(yīng)用程序中,我有一個(gè) UIWebView.

Inside my iOS Application I have an UIWebView.

現(xiàn)在我希望所有具有屬性 target="_blank" 的鏈接不要在我的 WebView 內(nèi)部打開(kāi),而是在 Safari 外部打開(kāi).

Now I want all links that have the attribute target="_blank" not to open inside my WebView but externally in Safari.

我該怎么做?

推薦答案

我的答案來(lái)自我在 Android WebView 的堆棧溢出中找到的答案.但實(shí)際上,兩個(gè) webview 都有相同的問(wèn)題和相同的(臟)修復(fù):

My answer, which is a from an answer I found on stack overflow for the Android WebView. But actually, both webview have the same problem and same (dirty) fix:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request     navigationType:(UIWebViewNavigationType)navigationType
{
    if ([request.URL.absoluteString hasPrefix:@"newtab:"])
    {
        // JS-hacked URl is a target=_blank url - manually open the browser.
        NSURL *url = [NSURL URLWithString:[request.URL.absoluteString substringFromIndex:7]];
        [[UIApplication sharedApplication] openURL:url];

        return true;
    }

    return true;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    // JS Injection hack to solve the target="_blank" issue and open a real browser in such case.
    NSString *JSInjection = @"javascript: var allLinks = document.getElementsByTagName('a'); if (allLinks) {var i;for (i=0; i<allLinks.length; i++) {var link = allLinks[i];var target = link.getAttribute('target'); if (target && target == '_blank') {link.setAttribute('target','_self');link.href = 'newtab:'+link.href;}}}";
    [webView stringByEvaluatingJavaScriptFromString:JSInjection];
}

這解決了在 safari 中打開(kāi) target="_blank" 的問(wèn)題,并在 webview 中保持打開(kāi)標(biāo)準(zhǔn)鏈接.

This solves both the target="_blank" issue to open in safari, AND keeps opening standard links within the webview.

這篇關(guān)于打開(kāi)目標(biāo)=“_blank";Safari 中 UIWebView 之外的鏈接的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Using Instruments to test an iOS app without having source code to the application(在沒(méi)有應(yīng)用程序源代碼的情況下使用 Instruments 測(cè)試 iOS 應(yīng)用程序)
KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動(dòng)運(yùn)行/壓力測(cè)試 iOS 應(yīng)用程序以找出罕見(jiàn) UI 錯(cuò)誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無(wú)法更改 Xcode 4.5 中的目標(biāo)成員身份可見(jiàn)性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態(tài)和動(dòng)態(tài)單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級(jí)到 Xcode 4.5 后,iOS 5 SDK 消失了)
主站蜘蛛池模板: 国产高清精品一区二区三区 | 国产1区在线 | 午夜免费精品视频 | 亚洲一区二区视频在线播放 | 国产在线二区 | 99国内精品 | 中文字幕成人av | 欧美成年视频 | 古装人性做爰av网站 | 日韩精品在线一区 | 亚洲精品第一页 | 国产福利视频导航 | 午夜欧美| 91久久精品国产 | 蜜臀久久99精品久久久久久宅男 | 国产日产精品一区二区三区四区 | 欧美一级免费黄色片 | 欧美综合在线观看 | 久久九九免费 | 久热久热 | 一区二区三区在线看 | 亚洲国产欧美在线 | 请别相信他免费喜剧电影在线观看 | 国产高清在线观看 | 日日碰狠狠躁久久躁婷婷 | 免费播放一级片 | 国产高清在线观看 | 作爱视频免费看 | 亚洲欧美日韩精品久久亚洲区 | 日韩精品成人在线 | 午夜精品在线观看 | 日本激情一区二区 | 国产一区二区在线播放 | a看片 | 日韩一区中文字幕 | 涩涩导航 | 青青久久久 | 欧美激情欧美激情在线五月 | 久久伊人一区 | 欧美一级在线免费观看 | 欧美aaa级|