If link is 'http://google.com', it worked, but if i change link to my pdf url, it doesn't open

前端 未结 2 1369
南方客
南方客 2020-12-22 14:50

window.open(\"http://google.com\") - works fine

window.open(\"data:application/pdf;base64,{base64EncodedString}\") - opens fine on iOS devi

相关标签:
2条回答
  • 2020-12-22 15:37

    Please use plugin file opener for that .Here is the plugin .

    run this command in your working directory .

    cordova plugin add cordova-plugin-file-opener2
    

    basic usage

    PDF File opener code

    cordova.plugins.fileOpener2.open(
        '/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
        'application/pdf', 
        { 
            error : function(e) { 
                console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
            },
            success : function () {
                console.log('file opened successfully');                
            }
        }
    );
    

    Please also check this url it is the plugin git directory and also have some example to open files. A File Opener Plugin for Cordova


    I would also suggest using In App Browser plugin.

    You can install it by running:

    cordova plugin add org.apache.cordova.inappbrowser
    

    in your CLI (in case if you are using Cordova 3.x). Earlier versions such (2.8.0, 2.9.0 etc) should have it pre-installed.

    Ton open PDF documents in a new window use:

    window.open('http://your-url.com/yourPDF.pdf', '_blank'); You might be able to use '_system option instead of '_blank' but i'm not sure about the outcome, it might open a system defined PDF viewer

    0 讨论(0)
  • 2020-12-22 15:43

    Looks like I have to use

    window.location.href = "data:application/pdf;base64,{base64EncodedString}"

    instead of window.open("data:application/pdf;base64,{base64EncodedString}");

    0 讨论(0)
提交回复
热议问题