3

YouTubeビデオを埋め込むウィジェットをダッシュ​​コードで作成しました。最初にインターネット接続をテストして、ユーザーに警告したいと思います。YouTubeウィジェットをiBooksに埋め込みました。時々、関係がない人もいると思います。


追加した場合:

 var online = window.navigator.onLine;
if (!online) {
alert("we are offline");
//console.log("We are offline!");
} else {
alert("we are online");
//console.log("We are online!");
}

そして、そのコードをウィジェットとしてiBooks Authorに追加すると、ポップアップは正常に機能しますが、アラートを確認する方法はありません。基本的に、それはiBookをロックします。何か案は?

4

1 に答える 1

1

ibook ダッシュボードについてはよくわかりませんが、http 接続を確認するために使用できる Web アプリ用のハートビート チェッカーを作成しました。

チェックする URL、max ttl、およびコールバックを指定してコードを呼び出します。ページが ttl (ミリ秒単位) の終わりまでに応答しなかった場合、コールバックが null で呼び出されます。それ以外の場合は、ステータスと要求オブジェクトを取得します。

function heartbeat(url, ttl, callback) {
    // Confirms active connection to server by custom URL response
    //
    if (!url) {
        url = "http://www.yourwebsitehere.com/yourpage?someheartbeatcall";
        // Replace with specific server heartbeat location and query string for cache busting
    }
    if (!ttl) {
        ttl = 1000; // Custom timeout in milliseconds
        // Replace with specific server heartbeat location and query string for cache busting
    }
    // Create the Ajax object
    var ajaxRequest;
    try{
            ajaxRequest = new XMLHttpRequest();
    }
    catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){
                // Unable to create
                callback(null);
                return;
            }
        }
    }
    // Set flag so only one pulse is recorded
    var called = false;
    // Make ajax call
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            if (!called) {
                called = true;
                callback(ajaxRequest.status, ajaxRequest);
            }
        }
    }
    ajaxRequest.open("GET", url, true);
    ajaxRequest.send(null); 
    // Make ttl timeout call
    var ttlcatch = setTimeout(function(){
        if (!called) {
            called = true;
            callback(null);
        }
    }, ttl);
    return;
}

var foo = false;
heartbeat("http://www.google.com", 1000, function(pulse){alert(pulse);} )
于 2012-04-09T01:05:47.407 に答える