JavaScript學習要點(八)

採用alert()、confirm()、prompt()方法可以調用系統對話框向用戶展示消息

confirm()對話框會有OK和Cancel兩個按鈕,OK返回true,Cancel返回false

prompt()會生成一個提示框,提示用戶輸入文本,有OK和Cancel,選擇OK返回輸入內容,選擇其他的返回Null

location對象用來返回當前窗口中加載文檔的有關信息,


function getQueryStringArgs(){
    var qs = (location.search.length > 0 ? location.search.substring(1) : "");
    args = {};
    items = qs.length ? qs.split("&") : [];
    item = null;
    value = null;
    name = null;

    i = 0;
    len = item.length;

    for (i = 0; i < len; i++) {
        item = items[i].split("=");
        name = decodeURIComponent(item[0]);
        value = decodeURIComponent(item[1]);

        if (name.length) {
            args[name] = value;
        }
    }

    return args;
}

使用location對象的位置操作可以改變瀏覽器的位置
location.href = “URL” //立即打開新URL


調用location的replace方法,不會產生歷史紀錄,無法後退

navigator方法



可通過遍歷navigator的plugins數組來檢測插件
但在IE中無效



history對象用來前進和後退
history.go(1);
history.go(-1);
history.go(2);

也可以傳給這個函數一個字符串參數,會跳轉到包含該字符串的第一個位置,可能前進也可能後退

history.back();
history.forward();
也可實現前進與後退





發佈了45 篇原創文章 · 獲贊 2 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章