鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ 環(huán)信登錄后跳轉(zhuǎn)到其它頁面

環(huán)信登錄后跳轉(zhuǎn)到其它頁面

假如我的登錄頁面為login.html建立環(huán)信連接

    //初始化,創(chuàng)建連接
    var conn = new WebIM.connection({
        isMultiLoginSessions: WebIM.config.isMultiLoginSessions,
        https: typeof WebIM.config.https === 'boolean' ? WebIM.config.https : location.protocol === 'https:',
        url: WebIM.config.xmppURL,
        heartBeatWait: WebIM.config.heartBeatWait,
        autoReconnectNumMax: WebIM.config.autoReconnectNumMax,
        autoReconnectInterval: WebIM.config.autoReconnectInterval,
        apiUrl: WebIM.config.apiURL,
        isAutoLogin: true
    });
    //登錄
    var login = function(user) {
        myAccount = user.user
        var pwd = user.pwd
        var options = {
            apiUrl: WebIM.config.apiURL,
            user: myAccount,
            pwd: pwd,
            appKey: WebIM.config.appkey,
            success: function(res) {
                //登錄成功后跳轉(zhuǎn)到主頁
                window.location.href="home.html"
            },
            error: function(res) {
                console.info(res)
            }
        };
        conn.open(options);
        return conn
    },
   

從login.html登錄成功后跳轉(zhuǎn)到home.html中,在home.html中還要寫建立鏈接的代碼和登錄代碼

    //初始化,創(chuàng)建連接
    var conn = new WebIM.connection({
        isMultiLoginSessions: WebIM.config.isMultiLoginSessions,
        https: typeof WebIM.config.https === 'boolean' ? WebIM.config.https : location.protocol === 'https:',
        url: WebIM.config.xmppURL,
        heartBeatWait: WebIM.config.heartBeatWait,
        autoReconnectNumMax: WebIM.config.autoReconnectNumMax,
        autoReconnectInterval: WebIM.config.autoReconnectInterval,
        apiUrl: WebIM.config.apiURL,
        isAutoLogin: true
    });
    //登錄
    var login = function(user) {
        myAccount = user.user
        var pwd = user.pwd
        var options = {
            apiUrl: WebIM.config.apiURL,
            user: myAccount,
            pwd: pwd,
            appKey: WebIM.config.appkey,
            success: function(res) {
                // 在home頁登錄成功后執(zhí)行相應(yīng)的代碼
            },
            error: function(res) {
                console.info(res)
            }
        };
        conn.open(options);
        return conn
    },

這樣覺得好麻煩,有沒有什么簡單方法,在登錄頁面后登錄成功后,在主頁直接寫邏輯呢

回答
編輯回答
我不懂

登錄后獲取的Access_token,用這個去請求數(shù)據(jù),還有建立連接的方法放在共用的js里面https://github.com/shmilylbel...

2017年5月26日 16:52