javascript - cordova 插件无法工作

标签 javascript cordova phonegap-plugins cordova-plugins

我安装了 Cordova 插件。一切都很成功,直到我尝试使用该插件。 我只需要这个插件就可以在 Android 上运行。 这是我正在尝试使用的插件:

http://plugins.cordova.io/#/package/net.yoik.cordova.plugins.screenorientation

我确实看到该插件已安装到我的目录中(plugins --> net.yoik.cordova.plugins.screenorientation)。

我的 JavaScript 代码:

window.onload = function () {

// access current orientation
console.log('Orientation is ' + screen.orientation);

screen.lockOrientation('portrait');

// access current orientation
console.log('Orientation is ' + screen.orientation);
};

console.log 显示“未定义”。

我的 config.xml 文件:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello"
    version="0.0.1"
    xmlns="http://www.w3.org/ns/widgets"
    xmlns:gap = "http://phonegap.com/ns/1.0"
    xmlns:cdv="http://cordova.apache.org/ns/1.0">


<name>Shoot Out</name>

<author email="dev@cordova.apache.org" href="http://cordova.io">
    Apache Cordova Team
</author>

<preference name="permissions"                value="none"/>

<!-- Customize your app and platform with the preference element. -->
<preference name="orientation"                value="default" />
<preference name="target-device"              value="universal" />
<preference name="fullscreen"                 value="false" />  
<preference name="webviewbounce"              value="false" /> 
<preference name="prerendered-icon"           value="true" />
<preference name="stay-in-webview"            value="true" />
<preference name="ios-statusbarstyle"         value="black-opaque" />
<preference name="detect-data-types"          value="true" />  
<preference name="exit-on-suspend"            value="false" /> 
<preference name="show-splash-screen-spinner" value="true" />  
<preference name="auto-hide-splash-screen"    value="true" />     
<preference name="disable-cursor"             value="false" />   
<preference name="android-minSdkVersion"      value="7" />     
<preference name="android-installLocation"    value="auto" />

<!-- Plugins -->
<gap:plugin name="net.yoik.cordova.plugins.screenorientation" version="1.3.1" />
<access origin="*" />

我的索引文件:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="format-detection" content="telephone=no"/>
<meta name="msapplication-tap-highlight" content="no"/>
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<!--<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=4, maximum-scale=1, minimum-scale=1, height=device-height, target-densitydpi=device-dpi" />-->
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, target-densitydpi=low-dpi, user-scalable=0"/>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>

<!-- FIREBASE CONNECTION -->
<script src="https://cdn.firebase.com/js/client/2.0.4/firebase.js"></script>

<script src="js/getCurrentGames.js"></script>
<script src="js/main.js"></script>
<title>Groot Project</title>
</head>
<body>
<div id="all"></div>
</body>
</html>

我在我的电脑和手机(android)上尝试过,都出现相同的错误。有什么想法吗?

最佳答案

我通过添加以下内容修复了它:

<script type="text/javascript" src="cordova.js"></script>

到我的index.html

关于javascript - cordova 插件无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27961033/

相关文章:

javascript - 无法将嵌套对象传递给 res.render()?

javascript - 缩短条件语句?

javascript - 如何在不同的浏览器中使用 DOM 内部的 activeElement.tagName ?

android - Phonegap(应用程序错误...发生网络错误)

android - 在 Cordova 推送通知

javascript - 在不刷新页面的情况下更改调整大小的内容?

javascript - 侧边导航随滚动移动

javascript - 处理 SQL :0 PhoneGap SQL 时出错

jQuery Mobile Cordova (Phonegap) 在每个页面底部留下空白

android - Ionic 应用程序在 Android 模拟器和设备上崩溃