如何将数据发送到另一个页面而不将其附加到URL? [英] how can i send the data to another page without appending it in url?

查看:79
本文介绍了如何将数据发送到另一个页面而不将其附加到URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,当用户点击某个链接时,他被定向到一个页面,我想在其中添加一个代码来获取变量并重定向到另一个页面。

i have a scenario where user when click on a link, he is directed to a page in which i want to add a code to fetch a variable and redirect to another page.

.ie用户点击< a href =sample.tpl>点击此处< / a>

on sample.tpl我想写一个代码将他重定向到另一个页面

on sample.tpl i want to write a code to redirect him to another page

<script>
window.location="http://mydomain.com/?page_id=10"

但我想在这个新链接上发送一个变量而不会出于安全原因将其附加到网址

我怎么能用一些安全的程序来做。

how can i do it with some safe procedure.

如果不清楚,请问我问题。

Do ask me questions plz if it is not clear.

推荐答案

您可以使用 method =post创建一个表单,隐藏输入您要传​​递的值,并将提交按钮设置为常规链接(如果您还想手动发送表单) 。

You could create a form with method="post", a hidden input with the value you want to pass and a submit button styled as a regular link (if you want to also manually send the form).

然后只需通过 submit()方法手动或以编程方式提交表单

Then just submit the form manually or programmatically through the submit() method

示例(页面加载后3秒后自动重定向)
http://jsbin.com/avacoj/1/edit

Example (with automatic redirect after 3 seconds after page load) http://jsbin.com/avacoj/1/edit

Html

<form method="post" action="http://mydomain.com/" id="f">
   <input type="hidden" name="page_id" value="10">
   <noscript><button type="submit">Continue</button></noscript> /* see below */
</form>

Js

window.onload = function() {
  var frm = document.getElementById('f');
  setTimeout(function() {
      frm.submit();
  }, 3000);
};

作为附注,您可以考虑插入 submit c>< noscript>< / noscript> 标签内的$ c>按钮,即使用户设备上没有js,重定向仍然可能,因此页面仍然是可以访问。

As a side note you may consider to insert a submit button inside <noscript></noscript> tag so the redirect will be possibile even when js is not available on the user device, so the page is still accessible.

这篇关于如何将数据发送到另一个页面而不将其附加到URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆