Javascript - How to get documents referrer with ha

2019-08-06 13:37发布

I wonder if this is possible. I was trying to access the referrer of the document inside an iframe but it always disregard the hash(#) value.

Root Page(index.html) - (http://example.com/test#hashvalue)

Inside the Root Page, there is an iframe that gets the referrer. It has this piece of code

var referrer = document.referrer;

This returns http://example.com/test without the hash value. Is there a way to get the full url(with hash) as a referrer.

Note: that I dont have access to Root page. If I do, I can use postMessage but I don't. The iframe was just embedded(Lets call it as a widget of the root page).

1条回答
小情绪 Triste *
2楼-- · 2019-08-06 14:16

Any url that contains the # character is a fragment url. The portion on the right of the # (that you want to access) is a fragment identifier i.e. a location within the page.
The browsers do not implement document.referrer to pass this identifier, this is in line with HTTP_REFERRER header passed to web pages.

If both of your iframes are from same domain i.e you are able to access parent.location from the child, then you can get the hash portion using parent.location.hash. Hard luck otherwise

查看更多
登录 后发表回答