用于apache的javascript代码Cordova在模拟器上工作Ripple但不在Live windows phone Device(L 535)

时间:2015-10-20 01:36:09

标签: javascript visual-studio-cordova apache-cordova

我在index.js中写了一个只是一个测试javascript代码,这是一个普通的alert(),当我在ripple上测试它作为android它工作正常,当我在我的Windows Phone上测试它显示

    #include "stdafx.h"
#include <iostream> 
#include <windows.h> // Microsoft Windows’ main library. 
#include <tchar.h> // Needed for _TEXT macro. 
#include "Strsafe.h" // Microsoft's library for secure strings.

using namespace std;
typedef wchar_t* LPWSTR, *PWSTR;
int layer = 0;

int recursionFindAbsraction(LPWSTR Dir, LPWSTR FilNam, LPWSTR filePath);
//original directory, new directory with *.* attached
//new directory with entire directory, new entire directory with *.* attached
int _tmain(int argc, _TCHAR* argv[])
{
    wchar_t holder[MAX_PATH];//using this instead of string
    wchar_t direct[MAX_PATH];
    wchar_t filePath[MAX_PATH];

    wcout << "Please enter the directory you wish to search: " << endl;
    wcin >> direct;
    wcout << direct << endl;


    wcout << "Please enter the filename (program will automatically seach for all files like it): " << endl;
    wcin >> holder;
    wcout << holder << endl;

    recursionFindAbsraction(direct, holder, filePath);
    getchar();
    getchar();
    return 0;

}

int recursionFindAbsraction(LPWSTR Dir, LPWSTR FilNam, LPWSTR filePath){
    WIN32_FIND_DATAW ptrFileData;
    HANDLE hFile = NULL;
    BOOL bGetNext = true;

    wchar_t newDir[MAX_PATH];
    wchar_t newDir2[MAX_PATH];
    wchar_t filePathHolder[MAX_PATH];

    //add slash then put directory into new variable, newDir
    StringCchCatW(Dir, MAX_PATH, _TEXT("\\"));

    //Here, we split the path to avoid appending *.* to the current directory
    StringCchCopyW(filePathHolder, MAX_PATH, Dir);
    StringCchCopyW(newDir, MAX_PATH, Dir);
    StringCchCopyW(newDir2, MAX_PATH, Dir);
    StringCchCatW(newDir2, MAX_PATH, _TEXT("*.*"));
    hFile = FindFirstFile(newDir2, &ptrFileData);

    if (hFile == INVALID_HANDLE_VALUE)
    {
        printf("FindFirstFile failed (%d)\n", GetLastError());
        getchar();
        //return 0;
    }

    while (bGetNext){

        if ((ptrFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0)
        {
            int setLoop = (ptrFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
            wcout << " file Attribute bitwise: " << setLoop;
            wcout << "file hidden " << endl;
            int counter = 0; counter++;
            wcout << "counter: " << counter << endl;
            wcout << "string compare: " << _wcsicmp(ptrFileData.cFileName, _TEXT("..")) << endl;
            wcout << "filename: " << ptrFileData.cFileName << endl;
            Sleep(100);
            /*
            if (_wcsicmp(ptrFileData.cFileName, _TEXT(".")) == 0){
                wcout << "Breaking1. " << endl;
                continue;
            }
            if (_wcsicmp(ptrFileData.cFileName, _TEXT("..")) == 0){
                wcout << "Breaking2. " << endl;
                continue;
            }*/
        }

        else
        {
            if (_wcsicmp(ptrFileData.cFileName, FilNam) == 0){
                wcout << "The first file found is: " << ptrFileData.cFileName << endl;
                //_tprintf(TEXT("The first file found is %s\n"), ptrFileData.cFileName);
                FindClose(hFile);
                //getchar();
                break;
            }
            if ((((ptrFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)) && ((ptrFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0))
            {//must check to see if folder
                layer++;
                wcout << "Layer: " << layer << endl;
                ptrFileData.cFileName;
                //when this gets called because it's a folder, the name
                //gets added to the wrong directory
                StringCchCatW(newDir, MAX_PATH, ptrFileData.cFileName);
                wcout << " newDir/fulldir: " << newDir<< endl;
                //resolves full path name at this point
                wcout << "filePathHolder from last else: " << filePathHolder << endl;
                wcout << "filename: " << ptrFileData.cFileName << endl;

                recursionFindAbsraction(newDir, FilNam, filePath);

            }

        }
        wcout << "&ptrFileData: " << &ptrFileData << endl;
        wcout << "hFile: " << hFile << endl;
        bGetNext = FindNextFile(hFile, &ptrFileData);
        wcout << " exit: " << bGetNext<< endl;
    }
    FindClose(hFile);
    return 0;
}

index.js

Unhandled exception at line 16, column 13 in
ms-appx://io.cordova.myapp16ff10/www/scripts/index.js

0x800a1391 - JavaScript runtime error: 'alert' is undefined

的index.html

(function () {
    "use strict";

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

    function onDeviceReady() {
        // Handle the Cordova pause and resume events
        document.addEventListener( 'pause', onPause.bind( this ), false );
        document.addEventListener('resume', onResume.bind(this), false);

        document.getElementById("btnTakePhoto").onclick = function () {
            alert("button working fine!");
        };

        // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
    };

    function onPause() {
        // TODO: This application has been suspended. Save application state here.
    };

    function onResume() {
        // TODO: This application has been reactivated. Restore application state here.
    };
} )();

Screenshot for Ripple (Android): it works fine!

Screenshot for Windows Phone (Lumia 535)

1 个答案:

答案 0 :(得分:2)

原因是因为Windows Phone 7和8中没有对alert的内置支持。请改用PhoneGap的Notification API,并使用以下内容:

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

function onDeviceReady() {
    window.alert = window.alert || navigator.notification.alert;
    alert('button working fine!');
}