---
title: "URL参数过长时post 跳转的方法（form替换location.href）"
author: "chengtong_java"
date: "2015-07-07T18:28:51Z"
tags: []
categories: ["Web前端"]
slug: "url-post-form-location-href"
draft: false
lastmod: "2015-07-07T18:28:51Z"
id: 2225039
url: "https://chengtong-java.iteye.com/blog/2225039"
---

在页面跳转时，我们时常用 window.location.href  的方法，如下：

window.location.href = 'monitor/queryalready\_count?param\_string='+param\_string;

注意：window.location.href 的跳转是 get 的跳转方式

 

但是当参数param\_string 过长时，比如参数字符串达到2K以上的长度，get跳转显然不可能了，就要使用form表单的形式实现post的方式跳转，可以在js中用以下方法实现：

 

```
document.write("<form action='monitor/queryalready_count' method='post' name='count_form' style='display:none'>");
document.write("<input type='hidden' name='param_string' value='"+param_string+"'");
document.write("</form>");
document.count_form.submit();
```