Cordova BlackBerry 10 WebWorks BlackBerry 10 PhoneGap网络视图URL

Cordova BlackBerry 10 WebWorks BlackBerry 10 PhoneGap网络视图URL,cordova,blackberry,webview,blackberry-10,blackberry-webworks,Cordova,Blackberry,Webview,Blackberry 10,Blackberry Webworks,我们目前正在使用BlackBerry WebWorks SDK开发phonegap应用程序,目前无法访问或控制WebView及其URL 它基本上是加载Index.html页面,这是我不想要的。我想在服务器上加载一些外部URL,一旦经过身份验证,服务器就会加载www文件夹的index.html。这是行不通的。知道如何控制WebView URL吗 谢谢, Ankit Tanna我刚刚用WebWorks 2.1/Cordova开发了一个应用程序,遇到了同样的挑战 首先,我的目标是跨平台,所以我正在使用

我们目前正在使用BlackBerry WebWorks SDK开发phonegap应用程序,目前无法访问或控制WebView及其URL

它基本上是加载Index.html页面,这是我不想要的。我想在服务器上加载一些外部URL,一旦经过身份验证,服务器就会加载www文件夹的index.html。这是行不通的。知道如何控制WebView URL吗

谢谢,
Ankit Tanna

我刚刚用WebWorks 2.1/Cordova开发了一个应用程序,遇到了同样的挑战

首先,我的目标是跨平台,所以我正在使用这个插件(尽管说实话,我不确定是否需要手动添加)

BlackBerry 10 WebView似乎不支持loadstart和exit事件,因此您必须使用计时器手动检查WebView的状态。大概是这样的:

var VIEWER = window.open('http://myauthenticationpage/login.html', '_blank', 'location=no,menubar=no,titlebar=no,toolbar=no,status=no');

//Start a timer to check for a URL change in the WebView
var AuthTimer = setInterval(function () {

    //Handle your failure case your own way, but stopping this loop is a good idea if the WebView isn't open
    if ((typeof VIEWER === 'undefined') || (typeof VIEWER.document === 'undefined')) {
        clearInterval(AuthTimer);
        return; 
    }

    //Get the current URL of the WebView
    var url = VIEWER.document.URL;

    //Process the URL in some way, like to extract a token
    //You can also access the DOM of the loaded page, as another option
    if (url.indexOf('authorizedUser=') > 0) {
        //Extract the username, which my server appends in the query string 
        var user = url.substring(url.indexOf('authorizedUser=') + 15);

        //I store the user token in localStorage
        localStorage.setItem('user', user);

        //Close the viewer and stope this timer
        clearInterval(AuthTimer);
        VIEWER.close();
    }
}, 20);
完成此操作后,您可能需要对服务器进行ajax调用以获取用户令牌或其他一些信息……具体取决于您的实现

所以当你的应用程序启动时,你的第一页应该立即做一个检查:我有一个存储的用户令牌吗?如果没有,则启动上述过程。继续启动它,直到我有一个存储的用户令牌。当我有一个令牌时,开始从服务器加载用户数据,或者从www/加载index.html,或者您想做的任何事情

这对我来说很好,而且设备处理得很好

Android/iOS的注意事项

如果您决定将其跨平台转移到Android或iOS,您可以改用事件:

var VIEWER = window.open('http://myauthenticationpage/login.html', '_blank', 'location=no,menubar=no,titlebar=no,toolbar=no,status=no');

VIEWER.addEventListener('exit', function(e) {
    //The webview closed!
    if (user == null) {
        //We still don't have a username
        setTimeout(function () {
            //Kick open the webview again, to try again for a username for example
            //(Might want to wrap all this in a function)
            VIEWER = window.open('http://myauthenticationpage/login.html', '_blank', 'location=no,menubar=no,titlebar=no,toolbar=no,status=no');
        }, 50);
    }
});

VIEWER.addEventListener('loadstart', function(e) {
    //The webview has started loading a new page
    var url = e.url;
    var user = null;

    if (url.indexOf('authorizedUser=') > 0) {
        user = url.substring(url.indexOf('authorizedUser=') + 15);

        localStorage.setItem('user', user);

        VIEWER.close();
    }
});
使用这种技术,当成功登录时,您的网页将需要“回显”查询字符串或响应DOM中的一些数据。我认为对于大多数授权实现,只需在请求中设置一个虚拟回调URL,然后在WebView URL中查看回调URL

我希望这有帮助

约翰