DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • A Data-Driven Approach to Application Modernization
  • JavaFX Goes Mobile
  • How To Scan and Validate Image Uploads in Java
  • 4 Expert Tips for High Availability and Disaster Recovery of Your Cloud Deployment
  1. DZone
  2. Coding
  3. Languages
  4. Visual comparisons of PhoneGap Notification UIs

Visual comparisons of PhoneGap Notification UIs

Raymond Camden user avatar by
Raymond Camden
·
May. 07, 13 · Interview
Like (0)
Save
Tweet
Share
4.13K Views

Join the DZone community and get the full member experience.

Join For Free

If you are a PhoneGap user, hopefully you know about the various aspects of the Notification API. The Notification API allows for visual, audio, and tactile notifications. In this post I want to focus on the visual notifications and how they differ from the built in web view notifications.

To begin, I created a simple HTML interface with buttons that would let me test alerts, confirms, and prompts. These are the three forms of visual notifications both in vanilla JavaScript as well as PhoneGap's Notification API.

<button id="jsAlert">JS Alert</button>
<button id="jsConfirm">JS Confirm</button>
<button id="jsPrompt">JS Prompt</button>

<p></p>

<button id="nAlert">Native Alert</button>
<button id="nConfirm">Native Confirm</button>
<button id="nPrompt">Native Prompt</button>

I used my epic CSS skills to make this a bit more touch friendly:

Now let's look at the JavaScript.

document.addEventListener('deviceready', deviceready, false);

function deviceready() {

    document.querySelector("#jsAlert").addEventListener("touchstart", function() {
        alert("JavaScript Alert");
    }, false);

    document.querySelector("#jsConfirm").addEventListener("touchstart", function() {
        var idontcare = confirm("This is a JavaScript Confirm?");
    }, false);

    document.querySelector("#jsPrompt").addEventListener("touchstart", function() {
        var istilldontcare = prompt("Answer this JavaScript Prompt","Some Default");
    }, false);

    document.querySelector("#nAlert").addEventListener("touchstart", function() {
        navigator.notification.alert("Native Alert", null, "Custom Title", "Custom Button");
    }, false);

    document.querySelector("#nConfirm").addEventListener("touchstart", function() {
        navigator.notification.confirm("This is a Native Confirm?", null, "Custom Title", "Bad,Good");
    }, false);

    document.querySelector("#nPrompt").addEventListener("touchstart", function() {
        navigator.notification.prompt("Answer this Native Prompt", null, "Custom Title",["NO!","OK"]);
    }, false);

}

The first three event handlers are for the vanilla JavaScript notifications. Notice how in confirm and prompt the result is handed back to a variable. The only real customization available is with the prompt method which allows for a default.

Here is the alert being fired:

Here is the confirm:

And finally the prompt:

Now let's consider the native options. First note that they allow for customization. In each one you can tweak the button (or buttons) as well as the title. Be aware that confirm takes a list of button labels while prompt takes an array. (I consider that a bug and I hope they fix that soon.) Also note that all three have callbacks for handling button presses. I've used null as a way of signifying I don't want to do anything, but you would normally have some kind of logic there.

Here is the native alert:

Here is the native confirm:

And lastly, the native prompt:

Just to be clear, do remember that you can build your own alerts, confirms, and prompts as well if you feel like it.




Comparison (grammar) JavaScript API CSS Testing Clear (Unix) HTML Label Interface (computing)

Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • A Data-Driven Approach to Application Modernization
  • JavaFX Goes Mobile
  • How To Scan and Validate Image Uploads in Java
  • 4 Expert Tips for High Availability and Disaster Recovery of Your Cloud Deployment

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: