---
title: "window.location.href以post方式传递参数的方法"
author: "colddemon"
date: "2012-07-26T17:07:51Z"
tags: []
categories: ["编程语言"]
slug: "window-location-href-post"
draft: false
lastmod: "2012-08-01T14:44:57Z"
id: 1608132
url: "https://colddemon.iteye.com/blog/1608132"
---

想用window.location.href跳转到另外一个界面。但直接传递get方法会暴露数据。
而用ajax或表单提交，有时在执行了方法后，无法跳转到另外的页面。
下面可以实现跳转的效果，却又能够通过post传递方法隐藏数据。
有一个不足就是，在跳转到新页面后，点击“返回”返回的是个空界面，再次点击才能返回到提交界面。


```java
<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>
```