1

XCode プロジェクトの www/Documents フォルダーに保存されているローカル PDF を開こうとしました。私が .js ファイルに入れたコードは次のとおりです。

Cordova.exec("ChildBrowserCommand.showWebPage", "file:///www/Documents"+pdf );

pdf はファイルの名前で、ファイルごとに変わります。シミュレーターでは正常に動作しますが、デバイスでは動作しません。どうすればこれを修正できますか?

ありがとう!

4

1 に答える 1

1

以下の関数を使用して子ブラウザにファイルをロードしています。内部ファイルをロードする場合に備えて、正しいローカル URL を作成します。

function loadChildBrowser(isInternal, URL) { 
        if(isInternal){ 
                var strPath = window.location.href; 
                var path = strPath.substr(0,strPath.lastIndexOf('/')) + URL; 
                cb.showWebPage(encodeURI(path)); 
        } 
        else{ 
                cb.showWebPage(URL); 
        } 
} 

編集

あなたのケースでこれを試してください:

    function loadChildBrowser(isInternal, URL) { 
            if(isInternal){ 
                    var strPath = window.location.href; 
                    var path = strPath.substr(0,strPath.lastIndexOf('/')) + URL; 
                    Cordova.exec("ChildBrowserCommand.showWebPage", encodeURI(path) ); 
            } 
            else{ 
                    Cordova.exec("ChildBrowserCommand.showWebPage", URL ); 
            } 
    }
于 2012-06-25T07:28:21.357 に答える