gpt4 book ai didi

javascript - 如何在 deviceready 事件后运行脚本?

转载 作者:行者123 更新时间:2023-12-03 07:35:42 28 4
gpt4 key购买 nike

我在为 Cordova 应用程序运行 jasmine 测试时遇到了一个问题:我有一个 html 页面 (Jasmine 2.4 SpecRunner.html),其脚本位于 <head> 中。要加载的文件(插件、服务、 Controller 等)以及 <head> 中最后包含的文件是一个测试文件。我的 body 里有一个deviceready事件监听器。但是当我针对 android 模拟器运行测试时,我的测试总是在 deviceready 之前执行。 ,并且看不到插件(即错误“设备未定义”)。

所以问题是:如何在 deviceready 之后延迟测试文件的执行事件?

我的 SpecRunner.html:

    <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="msapplication-tap-highlight" content="no" />
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<title>SportsWellness</title>


<script src="scripts/winstore-jscompat.js"></script>

<link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-2.4.1/jasmine_favicon.png">
<link rel="stylesheet" href="jasmine/lib/jasmine-2.4.1/jasmine.css">

<!-- Jasmine Modules -->

<script src="jasmine/lib/jasmine-2.4.1/jasmine.js"></script>
<script src="jasmine/lib/jasmine-2.4.1/jasmine-html.js"></script>
<script src="jasmine/lib/jasmine-2.4.1/boot.js"></script>

<!-- SportsWellness references -->
<link rel="stylesheet" href="css/app.css" />

<!-- AngularJS modules -->
<script src="libs/angular.min.js"></script>
<script src="libs/angular-resource.min.js"></script>
<script src="libs/angular-ui-router.js"></script>
<script src="libs/angular-touch.min.js"></script>
<script src="libs/angular-animate.min.js"></script>
<script src="libs/angular-mocks.js"></script>

<!-- Cordova reference, this is added to app when it's built. -->
<script src="cordova.js"></script>

<!-- Include Application scripts -->
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/router.js"></script>
<script type="text/javascript" src="js/platformOverrides.js"></script>

<!-- Include Controllers-->
<!-- Script tags -->

<!-- Include Services -->
<!-- Script tags -->

<!-- Include Directives -->
<!-- Script tags -->

<!-- Include Configuration Scripts -->
<!-- Script tags -->

<!-- Include specs to run -->
<script src="tests/ServicesTests/ReminderService.spec.js"></script>

</head>
<body>
<script type="application/javascript">
document.addEventListener('deviceready', function () {
navigator.splashscreen.hide();
}, false);
</body>
</html>

最佳答案

解决方案并不像我想要的那么漂亮,但我更改了 jasmine/boot.js 文件,并将 window.onload 函数替换为 document.addEventListener('deviceready', . ..)

关于javascript - 如何在 deviceready 事件后运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35625203/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com