Open a local pdf file with cordova

2019-03-31 02:00发布

Im using cordova 3.3.0 and i would like to open a local pdf file and then close it on user demand.

ref = window.open(encodeURI(path), '_blank', 'location=yes');
ref.addEventListener('exit', function() {
    ref.removeEventListener('exit', function(){});
    ref.close();

} );

This opens a file in inapp browser but i cannot get back to the actual app when I open some pdf file. How to add some close button or something ?

Im trying to get this working on ios.

2条回答
走好不送
2楼-- · 2019-03-31 02:15

Long time since you asked this but just had exactly the same issue. I had to install the inAppBrowser plugin on my project and the Done button appeared. Without the plugin installed, the pdf opened but the Done button was not shown.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-03-31 02:15

What you have should work. On iOS a "Done" button should appear in the lower left of the screen.

enter image description here

function openPDF(){
            ref = window.open('http://static.googleusercontent.com/media/www.google.com/en/us/webmasters/docs/search-engine-optimization-starter-guide.pdf', '_blank', 'location=yes');
            ref.addEventListener('exit', function() {
                ref.removeEventListener('exit', function(){});
                ref.close();
            } );
        }

I tested on iOS 6.1 and iOS 7. Of course you can set location=no to remove the URL at the bottom.

查看更多
登录 后发表回答