navigator.notification.alert不起作用

时间:2016-04-13 10:06:41

标签: javascript jquery phonegap-plugins cordova-plugins

这是Html代码:

<body bgcolor="#f2f3f4">
    <div class="heading">
         <p align="center" >Add Lead</p>
        <img class="img" onClick="back()" src="css/arrow.png" />
    </div>
    <br><br><br>

      <form  class="form-horizontal">
            <div class="col-md-4">
        <p><b>Company Name</b>
        <br>
        <input type="text" ID="companyname" style="height:25px;width:200px;"></p>
        </div>
           <div class="col-md-4">
        <p><b>Contact Name</b><br>
        <input type="text" ID="contactname" style="height:25px; width:200px;"></p>
        </div>

           <div class="col-md-4">
        <p><b>Contact Number</b><br>
        <input type="tel" ID="number" style="height:25px; width:200px;"></p>
        </div>
            <div class="col-md-4">
        <p><b>Email-Id</b><br>
        <input type="text" ID="email" style="height:25px; width:200px;"></p>
        </div>
            <div class="col-md-4">
        <p><b>Address</b><br>
        <input type="text" ID="address" style="height:60px; width:200px;">
        </input></p>
        </div>
            <div class="col-md-4">
        <p><b>Lead Details</b><br>
        <input type="text" ID="leaddetails" style="height:60px; width:200px;">
        </input></p>
        </div>
            <div class="col-md-4">
        <p><b>Lead Value</b><br>
        <input type="tel" ID="leadvalue" style="height:25px; width:200px;"></p>
        </div>
            <div class="col-md-4">
        <p><b>Follow Up Action</b><br> 
        <input type="text" ID="follwup" style="height:25px; width:200px;"></p>
        </div>
            <div class="col-md-4">
        <p><b>Lead Date</b><br>
        <input   class="form-control" type="date" value="date" ID="ldate" style="height:25px; width:200px;"></p>
        </div>
          <div class="col-md-4">
        <p><b>Follow Up Date</b><br>
        <input  class="form-control" type="date" value="date" ID="fdate" style="height:25px; width:200px;"></p>
        </div>
          <div class="col-md-4">
        <p><b>Status</b><br>
        <select  class="form-control" ID="status" style="height:25px; width:200px;">
        <option>open</option>
        <option>pending</option>
        <option>closed</option></select></p>
        </div>
        <div class="col-md-4">
        <p><b>Category</b><br>
        <select class="form-control" ID="category" style="height:25px; width:200px;">
        <option>hospital</option>
        <option>company</option>
        <option>institution</option>
        <option>other</option></select></p>
        </div>
    </form>

    </div>
    <div class="footer">

        <button id="cancle" onClick="cancelactivity()" style="right:50%;">Cancel</
            button>
        <button id="save" onClick="newleadpostactivity()" style="left:50%;">Save</button>

    </div>

JS:

function newleadpostactivity(){

var emailId,password;
var reponse;
var request = new XMLHttpRequest();

emailId=localStorage.getItem("userid");

companyName=document.getElementById("companyname").value;

if (companyName == null || companyName == "") {
    navigator.notification.alert("Company Name must be filled out");
    return false;
}
contactName=document.getElementById("contactname").value;
if (contactName == null || contactName == "") {
    navigator.notification.alert("Contact Name must be filled out");
return false;
}
    address=document.getElementById("address").value;
if (address == null || address == "") {
    navigator.notification.alert("Address must be filled out");
    return false;
}
 followUpAction=document.getElementById("follwup").value;
if (followUpAction == null || followUpAction == "") {
    navigator.notification.alert("Follow Up Action must be filled out");
   return false;
}
leadsDetails=document.getElementById("leaddetails").value;
if (leadsDetails == null || leadsDetails == "") {
    navigator.notification.alert("Leads Details must be filled out");
    return false;
}
 leadValue=document.getElementById("leadvalue").value;
if (leadValue == null || leadValue == "") {
    navigator.notification.alert("Lead Value must be filled out");
    return false;
}
leadDate=document.getElementById("ldate").value;
if (leadDate == null || leadDate == "") {
    navigator.notification.alert("Lead Date must be filled out");
return false;
}
 followUpDate=document.getElementById("fdate").value;
if (followUpDate == null || followUpDate == "") {
    navigator.notification.alert("Follow Up Date must be filled out");
return false;
}
 status=document.getElementById("status").value;
if (status == null || status == "") {
    navigator.notification.alert("Status must be filled out");
 return false;
}
  category=document.getElementById("category").value;
if (category == null || category == "") {
    navigator.notification.alert("Category must be filled out");
    return false;
}
 cemail=document.getElementById("email").value;
if (cemail == null || cemail == "") {
    navigator.notification.alert("Customer Email must be filled out");
   return false;
}
  cnumber=document.getElementById("number").value;
if (cnumber == null || cnumber == "") {
    navigator.notification.alert("Customer Number Up Date must be filled out");
  return false;
}

配置:

 <?xml version='1.0' encoding='utf-8'?>
 <widget id="com.PhoneGap.SalesPropeller" version="1.0.0"  xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<preference name="AllowInlineMediaPlayback" value="false" />
<preference name="BackupWebStorage" value="cloud" />
<preference name="DisallowOverscroll" value="false" />
<preference name="EnableViewportScale" value="false" />
<preference name="KeyboardDisplayRequiresUserAction" value="true" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
<preference name="SuppressesIncrementalRendering" value="false" />
<preference name="GapBetweenPages" value="0" />
<preference name="PageLength" value="0" />
<preference name="PaginationBreakingMode" value="page" />
<preference name="PaginationMode" value="unpaginated" />
<feature name="LocalStorage">
    <param name="ios-package" value="CDVLocalStorage" />
</feature>
<feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" />
    <param name="onload" value="true" />
</feature>
<preference name="StatusBarOverlaysWebView" value="true" />
<preference name="StatusBarStyle" value="lightcontent" />
<feature name="Notification">
    <param name="wp-package" value="Notification"/>
</feature>
<feature name="Notification">
    <param name="ios-package" value="CDVNotification" />
</feature>
<feature name="Notification">
    <param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<name>SalesPropeller</name>
<description>Smart Sale Management Application that respond to Big Enterprise Business</description>
<author email="support@phonegap.com" href="http://phonegap.com">PhoneGap Team</author>
<content src="index.html" />
<preference name="permissions" value="none" />
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="false" />
<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="10" />
<preference name="android-installLocation" value="auto" />
<gap:plugin name="org.apache.cordova.battery-status" />
<gap:plugin name="org.apache.cordova.camera" />
<gap:plugin name="org.apache.cordova.media-capture" />
<gap:plugin name="org.apache.cordova.console" />
<gap:plugin name="org.apache.cordova.contacts" />
<gap:plugin name="org.apache.cordova.device" />
<gap:plugin name="org.apache.cordova.device-motion" />
<gap:plugin name="org.apache.cordova.device-orientation" />
<gap:plugin name="org.apache.cordova.dialogs" />
<gap:plugin name="org.apache.cordova.file" />
<gap:plugin name="org.apache.cordova.file-transfer" />
<gap:plugin name="org.apache.cordova.geolocation" />
<gap:plugin name="org.apache.cordova.globalization" />
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="org.apache.cordova.media" />
<gap:plugin name="org.apache.cordova.network-information" />
<gap:plugin name="org.apache.cordova.splashscreen" />
<gap:plugin name="org.apache.cordova.vibration" />
<icon src="icon.png" />
<icon gap:platform="android" gap:qualifier="ldpi" src="www/res/icon/android/icon-36-ldpi.png" />
<icon gap:platform="android" gap:qualifier="mdpi" src="www/res/icon/android/icon-48-mdpi.png" />
<icon gap:platform="android" gap:qualifier="hdpi" src="www/res/icon/android/icon-72-hdpi.png" />
<icon gap:platform="android" gap:qualifier="xhdpi" src="www/res/icon/android/icon-96-xhdpi.png" />
<icon gap:platform="blackberry" src="www/res/icon/blackberry/icon-80.png" />
<icon gap:platform="blackberry" gap:state="hover" src="www/res/icon/blackberry/icon-80.png" />
<icon gap:platform="ios" height="57" src="www/res/icon/ios/icon-57.png" width="57" />
<icon gap:platform="ios" height="72" src="www/res/icon/ios/icon-72.png" width="72" />
<icon gap:platform="ios" height="114" src="www/res/icon/ios/icon-57-2x.png" width="114" />
<icon gap:platform="ios" height="144" src="www/res/icon/ios/icon-72-2x.png" width="144" />
<icon gap:platform="webos" src="www/res/icon/webos/icon-64.png" />
<icon gap:platform="winphone" src="www/res/icon/windows-phone/icon-48.png" />
<icon gap:platform="winphone" gap:role="background" src="www/res/icon/windows-phone/icon-173-tile.png" />
<gap:splash gap:platform="android" gap:qualifier="port-ldpi" src="www/res/screen/android/screen-ldpi-portrait.png" />
<gap:splash gap:platform="android" gap:qualifier="port-mdpi" src="www/res/screen/android/screen-mdpi-portrait.png" />
<gap:splash gap:platform="android" gap:qualifier="port-hdpi" src="www/res/screen/android/screen-hdpi-portrait.png" />
<gap:splash gap:platform="android" gap:qualifier="port-xhdpi" src="www/res/screen/android/screen-xhdpi-portrait.png" />
<gap:splash gap:platform="blackberry" src="www/res/screen/blackberry/screen-225.png" />
<gap:splash gap:platform="ios" height="480" src="www/res/screen/ios/screen-iphone-portrait.png" width="320" />
<gap:splash gap:platform="ios" height="960" src="www/res/screen/ios/screen-iphone-portrait-2x.png" width="640" />
<gap:splash gap:platform="ios" height="1136" src="www/res/screen/ios/screen-iphone-portrait-568h-2x.png" width="640" />
<gap:splash gap:platform="ios" height="1024" src="www/res/screen/ios/screen-ipad-portrait.png" width="768" />
<gap:splash gap:platform="ios" height="768" src="www/res/screen/ios/screen-ipad-landscape.png" width="1024" />
<gap:splash gap:platform="winphone" src="www/res/screen/windows-phone/screen-portrait.jpg" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<access launch-external="yes" origin="mailto:*" />
<access launch-external="yes" origin="tel:*" />
<feature name="InAppBrowser">
    <param name="ios-package" value="CDVInAppBrowser" />
</feature>
 </widget>

如果我使用普通提醒,它的工作正常,但如果我使用navigator.notification.alert则无效。在我的应用的其他页面,它与navigator.notification.alert一起正常工作。

知道为什么这仍然不起作用?

谢谢。

2 个答案:

答案 0 :(得分:0)

在应用的每个页面中,您都应该包含 cordova.js 文件,并且在设备就绪事件被触发后,您可以使用任何插件或API。

希望它会对你有所帮助。

答案 1 :(得分:0)

如Naresh所述,请确保您在HTML中引用了cordova.js。您还需要确保您对Cordova插件的所有调用都在deviceready()事件处理程序中完成。像这样:

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

function onDeviceReady(){
    navigator.notification.alert('Hi');
}