function Goback(data) {
        if(data){
            msgShow('success_msg',  data.returnMsg);
        }    
        var urlGoBack = document.referrer;       
            setTimeout(function () {
                window.location.href = urlGoBack ;     //前一頁;
            }, 3000);
        }

最近開發的功能需要再表單送出後顯示訊息並返回上一頁

測試了幾種方法 最後使用了document.referrer 

使用下面幾種方式Alert出實際值

document.referrer 可以成功取得前一頁面url並返回頁面 

history.go(-1)  為返回前一動作且資料會cache,Alert後取不到url 值為undeifined

history.back(-1) 一樣Alert後取不到url 值為undeifined

文章標籤
全站熱搜
創作者介紹
創作者 andrea77222 的頭像
andrea77222

Andrea's Hello world

andrea77222 發表在 痞客邦 留言(0) 人氣(0)