1. 程式人生 > >Window.location.href以post方式傳遞引數的方法

Window.location.href以post方式傳遞引數的方法

原文地址:http://colddemon.iteye.com/blog/1608132

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

Java程式碼  收藏程式碼
  1. <script language=javascript>   
  2. document.write("<form action=abc.action method=post name=form1 style='display:none'>"
    );  
  3. document.write("<input type=hidden name=name value='"+username+"'/>");  
  4. document.write("</form>");  
  5. document.form1.submit();  
  6. </script>