Unable to access cordova.js for Cordova vibration feature

I'm attempting to create a basic Cordova app for Android that involves vibrating the phone when a button is clicked, but I can't seem to get it to work. I've been using PhoneGap and have included the cordova-plugin-vibration, but I keep getting an error message in the console saying

GET http://xxx.x.x.x:xxxxx/www/cordova.js
.

Even though cordova.js is located in the platform/android/assets/lib directory as expected, the vibration feature still isn't functioning. What could be causing this issue?

edit***

Below is the code I am currently utilizing:

html:

<body>
    <main>            
       <button id = "vibration">SHAKE IT</button>
    </main>

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

js:

onDeviceReady: function() {
    app.receivedEvent('deviceready');
    document.getElementById("vibration").addEventListener("click", vibration);
    },
function vibration() {
    var time = 3000;
    navigator.vibrate(time);
}

/Håkan

ps. I'm new to this so any assistance would be greatly appreciated.

Answer №1

When looking at the index.html file, it seems that cordova is included in this manner:

<script src="www/cordova.js"></script>

Consider changing it to

<script src="cordova.js"></script>

If this doesn't apply to your situation, providing more of your code could help to identify the issue ;)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Automatically simulate the pressing of the enter key in a text field upon page load using Javascript

I am looking to simulate the pressing of the enter key in a text field when a page is loaded. Essentially, I want the text field to automatically trigger the enter key press event as if it had been pressed on the keyboard by the user. Below is an example o ...

The program running on an Android device cannot be debugged using Android Studio 2.1.2

My current setup includes: Operating System: Windows 7 64 bit Android Studio Version: 2.1.2 Java Version: "1.8.0_102" Java Runtime Environment: Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java VM: Java HotSpot(TM) 64-Bit Server VM (build 25.102- ...

Having trouble deciphering the API or a specific one from React.js/Node.js/Axios/Fetch?

I'm facing some confusion regarding my code. I have tried different APIs and some work, while others cannot be accessed in react.js. Can anyone help me correct this issue? The APIs that are not working in react.js always return a typescript fetching f ...

Managing npm packages installed globally

I am really struggling to understand how node's globally installed packages behave. When I install a package like http-server globally, I can run it simply by typing http-server. http-server However, if I try to run it with node http-server, I encoun ...

What is the best way to set a default value using select2 and then activate an ajax request upon selection (select2:select

Upon loading my page, I want the first element of the selectbox to be automatically selected. While the element is getting selected, it doesn't trigger the ajax request as expected. My goal is for the 'select2: select' event to be triggered ...

Struggling to convert a CSV file into an array of objects

I have stored CSV files in my application and now I need to convert them into an array of objects using csv-parse. You can find more information about csv-parse here. When I try to require the csv file, I encounter the following error: Error: Ingredient ...

Styling nested divs in CSS

I am experiencing an issue where the child divs within parent divs are overflowing outside of the parent divs. To get a better understanding of the problem, please try running the code below in a browser: My goal is to align the innermost divs horizontall ...

Unable to locate web element using Selenium in C#

Here is the HTML code I am currently using: <div class="modal-footer"> <button class="btn btn-primary" type="button" value="Show Alert" ng-click="questions.getIrMessage()" data-dismiss="modal">Confirm</button> <button class ...

Error: Unable to locate font in the VueJS build

Within my config/index.js file, I have the following setup: ... build: { index: path.resolve(__dirname, 'dist/client.html'), assetsRoot: path.resolve(__dirname, 'dist'), assetsSubDirectory: 'static', assetsPub ...

The ngTable feature in AngularJS fails to initiate the getData function when making an HTTP request

I am currently working on integrating ngTable with AngularJS. After successfully installing all necessary Angular dependencies, everything seems to be functioning well. However, I am encountering an issue where my HTTP GET request is not triggering as ex ...

"Navigate with Ease: Introducing the Twitter Bootstrap Scroll

Having trouble with the twitter bootstrap scroll spy feature as the navigation doesn't update until midway through scrolling and skips item 4 to reach the last item. Check out this example: http://jsfiddle.net/eoboite/kjvAa/38/ What am I doing wrong? ...

Various CSS regulations for various languages/modes in CodeMirror

Can CodeMirror highlight different languages separately in multi-mode? .cm-s-default .cm-string-html {color: blue;} .cm-s-default .cm-string {color: #170;} Usually, CodeMirror applies the same class names for strings, comments, and other objects in all l ...

My Ajax request is hitting a snag - the success function isn't functioning as expected

Having an issue with the success function in my ajax call. It doesn't seem to be working as expected. Check out the code snippet below: var data1 = { "name": namedata[0], "email": namedata[1], "mobile": namedata[2], "company": namedata[3], "message" ...

JavaScript is often used for implementing API calls and filtering arrays

I am trying to create a function that generates a table using if and indexOf within a forEach loop. I want the table to only display if the input value matches the first item in an array with the name "germany". Can anyone help me figure out what I'm ...

Getting directions using the node-googlemaps module in node.js can be achieved by following these steps

For the past day, I've been attempting to make progress with this Node.js Google Maps directions example, but so far, no success. Every time I run it, I keep seeing ·· √ OK » 2 honored (0.848s). I've previously asked a similar question on U ...

problems with using includes() in the array every() method

Hi everyone, I've been spending quite a bit of time trying to find a solution to this problem and I'm hoping someone can help me out. The issue at hand is that I have 2 arrays - one containing multiple words from an address and another built wit ...

Error message: The aidl file encountered an issue where it was unable to locate the import for

I am currently working on a project that utilizes AIDL interfaces, and so far everything is going smoothly with building in Android Studio using Gradle. However, while Android Studio serves as a convenient IDE for developing my Android applications, I need ...

Changing tabs will redirect the url

Having an issue with ASP AjaxControlToolkit tabs. I want the URL to change based on the tab selected by the user. Check out the code snippet below: <asp:TabContainer ID="TabContainer1" runat="server" Width="100%" Height="100%"> <asp:TabPanel ...

Retrieve data from the table and dropdown menu by clicking a button

A script is in place that retrieves data from two columns (Members, Description) dynamically from the table upon button click. Table html Here is the JQuery code responsible for extracting values from the table: $(function() { $('#myButton') ...

Using Jquery and the cookie.split method to extract and eliminate a value from a cookie

I am trying to figure out how to remove a specific matching value from a cookie using JavaScript. I have written a script that loops over the cookie and checks for matches, but I can't seem to successfully remove just the matching value. Any tips on a ...