javascript 在javascript中隐藏url参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21580647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:14:19  来源:igfitidea点击:

Hide url parameters in javascript

javascriptjqueryquery-string

提问by Andrew Simpson

I am using this:

我正在使用这个:

document.location ='my different asp.net page?=myparams'

Is there a way to hide the values of the params in the URL displayed on the browser?

有没有办法隐藏浏览器上显示的 URL 中的参数值?

I know I could use hidden Form values and I know I can encrypt the values (which is what I will do if no joy here).

我知道我可以使用隐藏的 Form 值,我知道我可以加密这些值(如果这里没有乐趣,我会这样做)。

Is there a simpler tidier way of doing this? Perhaps via JQuery.

有没有更简单更整洁的方法来做到这一点?也许通过 JQuery。

回答by iii

If you are just trying to hide the url parameters from the address bar in the browser then you could use an iframe.

如果您只是想从浏览器的地址栏中隐藏 url 参数,那么您可以使用iframe

回答by HieuHT

One solution is to set document.location to a second page, that page keep param values in a session variable and redirect to your desired one.

一种解决方案是将 document.location 设置为第二页,该页将 param 值保留在会话变量中并重定向到您想要的。

document.location = "redirectpage.php?param=value"

document.location = "redirectpage.php?param=value"

In redirectpage.php

在redirectpage.php

$_SESSION['param']=$_GET['param]; header('Location: ' . desired_page?param=value);

$_SESSION['param']=$_GET['param]; 标头('位置:' .desired_pa​​ge?param=value);

By this way, value of param will be only displayed in a very short time when redirectpage.php redirecting to desired page.

这样,param 的值只会在redirectpage.php 重定向到所需页面时很短的时间内显示出来。

Hope it helps

希望能帮助到你

Btw, can you explain how hidden Form works in this case?

顺便说一句,你能解释一下隐藏表单在这种情况下是如何工作的吗?