1. 程式人生 > >window.location.href()採用post傳遞資料

window.location.href()採用post傳遞資料

http://colddemon.iteye.com/blog/1608132  轉載地址 網上都是這個版本,原創不知道是誰 就轉載他的吧

想用window.location.href跳轉到另外一個介面。但直接傳遞get方法會暴露資料。
而用ajax或表單提交,有時在執行了方法後,無法跳轉到另外的頁面。
下面可以實現跳轉的效果,卻又能夠通過post傳遞方法隱藏資料。
有一個不足就是,在跳轉到新頁面後,點選“返回”返回的是個空介面,再次點選才能返回到提交介面。    這是不足的地方,生產系統中應該不會採用此方法

但是還是記錄下來

    <script language=javascript>   
    document.write("<form action=abc.action method=post name=form1 style='display:none'>");  
    document.write("<input type=hidden name=name value='"+username+"'");  
    document.write("</form>");  
    document.form1.submit();  
    </script>