navigator.notification.alert 不起作用

Posted

技术标签:

【中文标题】navigator.notification.alert 不起作用【英文标题】:navigator.notification.alert is not working 【发布时间】:2016-04-13 10:06:41 【问题描述】:

这里是 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"  src="www/res/icon/ios/icon-57.png"  />
<icon gap:platform="ios"  src="www/res/icon/ios/icon-72.png"  />
<icon gap:platform="ios"  src="www/res/icon/ios/icon-57-2x.png"  />
<icon gap:platform="ios"  src="www/res/icon/ios/icon-72-2x.png"  />
<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"  src="www/res/screen/ios/screen-iphone-portrait.png"  />
<gap:splash gap:platform="ios"  src="www/res/screen/ios/screen-iphone-portrait-2x.png"  />
<gap:splash gap:platform="ios"  src="www/res/screen/ios/screen-iphone-portrait-568h-2x.png"  />
<gap:splash gap:platform="ios"  src="www/res/screen/ios/screen-ipad-portrait.png"  />
<gap:splash gap:platform="ios"  src="www/res/screen/ios/screen-ipad-landscape.png"  />
<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 正常工作。

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

谢谢。

【问题讨论】:

【参考方案1】:

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

希望对你有所帮助。

【讨论】:

【参考方案2】:

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

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

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

【讨论】:

以上是关于navigator.notification.alert 不起作用的主要内容,如果未能解决你的问题,请参考以下文章