2013-04-13 6 views

risposta

13

Se si modificano i collegamenti per utilizzare la nuova sintassi InAppBrowser, è facile aprire gli URL nel browser Web di sistema, InAppBrowser o nella visualizzazione Web effettiva dell'app.

Questo codice dovrebbe aprire l'URL nel browser sistema web (Safari su iOS):

<a href="#" onclick="var ref = window.open('http://google.com', '_system');"> 

Modifica '_system'-'_blank' aprirà l'URL nella InAppBrowser.

Cambiando '_system' a '_self' si aprirà l'URL nella visualizzazione Web della propria app (se il dominio è autorizzato) o InAppBrowser (se il dominio non è nella whitelist).

Esempio Gist: https://gist.github.com/wicketyjarjar/7043336

Nota: Cordova/PhoneGap 3.0 + richiede il plugin InAppBrowser per essere installato prima che questo funzionerà.

Per installare il plugin InAppBrowser (se necessario) ...

Utilizzando Cordova: cordova plugin add org.apache.cordova.inappbrowser

Utilizzando PhoneGap: phonegap local plugin add org.apache.cordova.inappbrowser

+0

provo a anche questo, ma non funziona open link in stesso AppBrowser –

+0

Funziona per me, ecco un esempio: https://gist.github.com/anonymous/5394042 – wicketyjarjar

+0

collegamento errato. va alla pagina 404 ... –

0

La mia soluzione è come qui di seguito: un primo momento ho definire una funzione di safario aperto:

LaunchNewWindow: function (url) {  
    if (window.location.toStringing().match(/file/i) && navigator.userAgent.match(/iPhone|iPad|iPod/i)) { 
    window.open(url+"_xex_", "_blank");} 
    else{ 
    window.open(url, "_blank"); 
    } 
} 

quindi hai e per modificare il codice in CordovaLic \ classses \ CDViewController.m (CordovalLib 3.0.0) per gestire il vostro URL spaziale: ho aggiunto in line685:

else { 

// start stoneskin's change: force open external url in safari        
           if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) { 
    NSString *myurlstr = [url absoluteString]; 
    if ([myurlstr rangeOfString:@"_xex_"].location != NSNotFound){ 
     myurlstr = [myurlstr stringByReplacingOccurrencesOfString:@"_xex_" withString:@""]; 
     NSURL *myurl = [NSURL URLWithString:myurlstr]; 
     [[UIApplication sharedApplication] openURL:myurl]; 
     return NO; 
    } 

} 
//end start stoneskin's change 
if ([self.whitelist schemeIsAllowed:[url scheme]]) { 
    return [self.whitelist URLIsAllowed:url]; 
} else { 
    if ([[UIApplication sharedApplication] canOpenURL:url]) { 
     [[UIApplication sharedApplication] openURL:url]; 
} else { // handle any custom schemes to plugins 
     [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; 
} 
} 

return NO; 
} 
Problemi correlati