2013-10-11 1 views
1

phonegap을 사용하려고하지만 어떤 이유로 내 javascript가 실행되고 있지 않습니다.Phonegap not javascript

<html> 
<head> 
    <meta charset="utf-8" /> 
    <meta name="format-detection" content="telephone=no" /> 
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
    <link rel="stylesheet" type="text/css" href="css/index.css" /> 
    <title>Hello World</title> 

    <script type="text/javascript" src="phonegap.js"></script> 
    <script type="text/javascript" charset="utf-8"> 
     document.addEventListner("deviceready", onDeviceReady, false); 

     function onDeviceReady() { 
      alert('hey'); 
      document.addEventListener("online", onOnline, false); 
      document.addEventListener("offline", onOffline, false); 
     } 

     function onOnline() { 
      alert('device is online'); 
     } 

     function onOffline() { 
      alert('device is offline'); 
     } 
    </script> 
</head> 
<body> 
    <div class="app"> 
     <h1>PhoneGap</h1> 
     <div id="deviceready" class="blink"> 
      <p class="event listening">Connecting to Device</p> 
      <p class="event received">Device is Ready</p> 
     </div> 
    </div> 
</body> 

하지만 어떤 이유로 나는 경고를 받고 있지 않다 : 무엇 내가 지금까지 시도하는 것입니다. 나는 IOS 나는 또한 tryed 무엇 7

에 폰갭 2.9.0를 사용하고 있습니다 것은 :

<html> 
<head> 
    <meta charset="utf-8" /> 
    <meta name="format-detection" content="telephone=no" /> 
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
    <link rel="stylesheet" type="text/css" href="css/index.css" /> 
    <title>Hello World</title> 

    <script type="text/javascript" src="phonegap.js"></script> 
    <script type="text/javascript" charset="utf-8"> 
     document.addEventListener("deviceready", onDeviceReady, false); 

// PhoneGap is ready 
// 
function onDeviceReady() { 
    // Empty 
} 

// alert dialog dismissed 
function alertDismissed() { 
    // do something 
} 

// Show a custom alert 
// 
function showAlert() { 
    navigator.notification.alert(
     'You are the winner!', // message 
     alertDismissed,   // callback 
     'Game Over',   // title 
     'Done'     // buttonName 
    ); 
} 
    </script> 
</head> 
<body> 
    <div class="app"> 
     <h1>PhoneGap</h1> 
     <div id="deviceready" class="blink"> 
      <p class="event listening">Connecting to Device</p> 
      <p class="event received">Device is Ready</p> 
      <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p> 
     </div> 
    </div> 
</body> 

+0

... 참고로 – opalenzuela

+0

일부 브라우저는'alert'을 표시하지 않습니다. 대신'console.log'을 시도하십시오 – CodingIntrigue

+0

대신에 사용해야하는 것은 무엇입니까? – Ajeo

답변

2
 document.addEventListener("online", onOnline, false); 
     document.addEventListener("offline", onOffline, false); 

이 함수는 새로운 인터넷 연결을 설정하고 네트워크 연결 만

을 해제에서 작동합니다

앱을 열 때 작동하지 않습니다. 이러한 이벤트 리스너 '온라인'과 '오프라인'은 주로 인터넷 연결이 가능한지 추적하는 데 사용됩니다.

은 또한 당신은 시도 경고

+0

하지만 왜 onDeviceReady()에 경고가 표시되지 않습니까? – Ajeo

+0

내 대답을 편집했습니다 –

+0

xcode 콘솔에 오류가 있는지 확인하십시오 –

0

에 대한 폰갭에서 IOS에서 7. 알림 클래스를 지원되지 않을 수 있습니다 경고 기능을 사용하지 않아야이는 내 말에 작업하고 추가 cordova.js

에 잊었 수 있습니다 iOS7에의 자바 스크립트는 "경고()"호출을 무시
<html> 
<head> 
    <meta charset="utf-8" /> 
    <meta name="format-detection" content="telephone=no" /> 
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
    <link rel="stylesheet" type="text/css" href="css/index.css" /> 
     <script type="text/javascript" src="cordova.js"></script> 
    <title>Hello World</title> 
    <script type="text/javascript" src="phonegap.js"></script> 
    <script type="text/javascript" charset="utf-8"> 
     document.addEventListener("deviceready", onDeviceReady, false); 

     // PhoneGap is ready 
     function onDeviceReady() { 
      // Empty 
     } 

    // alert dialog dismissed 
    function alertDismissed() { 
     // do something 
    } 

    // Show a custom alert 
    function showAlert() { 
     navigator.notification.alert(
            'You are the winner!', // message 
            alertDismissed,   // callback 
            'Game Over',   // title 
            'Done'     // buttonName 
            ); 
    } 
    </script> 
</head> 
<body> 
    <div class="app"> 
     <h1>PhoneGap</h1> 
     <div id="deviceready" class="blink"> 
      <p class="event listening">Connecting to Device</p> 
      <p class="event received">Device is Ready</p> 
      <p><a href="#" onclick="showAlert();">Show Alert</a></p> 
     </div> 
    </div> 
</body> 

+0

이것은 사용중인 phonegap의 버전에 따라 다릅니다. phonegap 3 이상에서는 cordova.js 또는 phonegap.js를 수동으로 포함하지 않아야합니다. 포함 된 파일은 프로젝트를 빌드 할 때 자동으로 추가됩니다. 그리고 phonegap.js가 cordova.js를로드하기 때문에 cordova.js와 phonegap.js를 포함해서는 안됩니다. – QuickFix