window.open to open local image,pdf on windows platform using InAppBrowser

谁说胖子不能爱 提交于 2019-12-23 15:44:40

问题


I am working on cordova based hybrid application targeted to Windows 8.1 platform with InAppBrowser plugin added. I have used following code to open local image/pdf file:

window.open("Screenshot.png", "_blank", "location=no");

But it does nothing...no exception and no image.

I am able to use the same code to open text file. But the same code does not work with image/pdf/word/excel documents.

Any help will be much appreciated.

Thanks, Chirag.

Update: I found solution. Following is the sample code:

var applicationData = Windows.Storage.ApplicationData.current;
                var localFolder = applicationData.localFolder;
                console.log(localFolder);

                var imageFile = "image.png";

                // Get the image file from the package's image directory
                localFolder.getFileAsync(imageFile).then(
                  function (file) {
                      console.log("1");
                      // Set the show picker option
                      var options = new Windows.System.LauncherOptions();
                      options.displayApplicationPicker = true;

                      // Launch the retrieved file using the selected app
                      Windows.System.Launcher.launchFileAsync(file, options).then(
                        function (success) {
                            if (success) {
                                // File launched
                                console.log("2");
                            } else {
                                // File launch failed
                                console.log("3");
                            }
                        });
                  });

Hope this helps someone.

Thanks.

来源:https://stackoverflow.com/questions/32935380/window-open-to-open-local-image-pdf-on-windows-platform-using-inappbrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!