Inappbrowser无法在iOS中运行

时间:2016-06-02 17:23:38

标签: javascript ios cordova

我正在尝试从iOS手机上加载PDF。当我尝试单击href链接时,PDF未加载到inappbrowser中。我添加了inappbrowser插件并更新了cordova.js和cordova_plugins.js。任何人都可以帮助我实现这个目标吗?提前致谢。到目前为止,我试过这个。

<script>
  var fileToInclude1='',fileToInclude2='';
  var standalone = window.navigator.standalone,
      userAgent = window.navigator.userAgent.toLowerCase(),
	  safari = /safari/.test( userAgent ),
	  ios = /iphone|ipod|ipad/.test( userAgent ),
	  androidversion = /version/.test( userAgent ),
	  android = /android/.test( userAgent );
	  if( ios ) {
		if ( !standalone && safari ) {
			//browser
		} else if ( standalone && !safari ) {
			//standalone
			fileToInclude1 = '../cordova/ios/cordova.js';
			fileToInclude2 = '../cordova/ios/cordova_plugins.js';
		} else if ( !standalone && !safari ) {
			//uiwebview
			fileToInclude1 = '../cordova/ios/cordova.js';
			fileToInclude2 = '../cordova/ios/cordova_plugins.js';
		}
	   } else {
			//not iOS
		    if (androidversion && android) {
			   //Android App
			   fileToInclude1 = '../cordova/android/cordova.js';
			   fileToInclude2 = '../cordova/android/cordova_plugins.js';
			} else {
				//browser
			}
		}
		var cordovaref = document.createElement("script");
		cordovaref.type = 'text/javascript';
		cordovaref.src = fileToInclude1;

		document.getElementsByTagName('head')[0].appendChild(cordovaref);

		document.addEventListener("deviceready",onDeviceReady,false);

		function onDeviceReady() {
			window.open = cordova.InAppBrowser.open;
		}

		function pdf(url){
			var ref = window.open(url, '_blank', 'location=yes');
		}

</script>

<div id="news_content">Please <a onClick="pdf('http://www.sample.org/sites/blog-images/ABC16_Full_Report.pdf')">click here</a> for News</div>

0 个答案:

没有答案