是否可以使用javascript从浏览器访问上一页的URL [英] Is it possible to get URL of previous page visited from browser using javascript

查看:70
本文介绍了是否可以使用javascript从浏览器访问上一页的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在第A页。

现在我点击第A页并重定向到第B页。
现在我点击第B页并重定向到页面A。

Now I click in page A and redirected to page B. Now I click in page B and redirected to page A.

这里我想知道B页的网址。

Here i want to know the url of page B.

我试过了document.referrer但是它不起作用。

I have tried document.referrer but its not working.

推荐答案

当用户点击链接导航到当前页面时,document.referrer工作但我不知道认为当你在Javascript函数中进行手动重定向时它会起作用。

document.referrer works when a user clicks on a link to navigate to the current page but I don't think it works when you do a manual redirect in a Javascript function.

我能想到的唯一方法是在用户重定向到当前页面之前存储页面的URL。

The only way I can think of is to store the URL of the page before the user is redirected to your current page.

您可以将其存储在隐藏的表单或cookie中。

You could store it in a hidden form or a cookie.

此问题之前也有人提出,值得快速阅读。 如何在Javascript中获取以前的网址?

This question has also been asked before and its worth having a quick read through here. How do you get the previous url in Javascript?

我从中获取了这个cookie示例,向您展示我的意思。

I took this cookie example from it to show you what I mean.

$.cookie("previousUrl", window.location.href, {path:"/"});

这篇关于是否可以使用javascript从浏览器访问上一页的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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