I have page A and B. in my page A, I have link that direct me to page B. What I want to do is, when I click the link in page A, it will open page B, and also give me alert of page A`s URL. Here is what I try:
page A:
<html>
<head>
<a href="file:///C:/Users/jason/Desktop/pageb.html">click me</a>
</head>
</html>
page B:
<html>
<head>
<script type="text/javascript">
var oldURL = document.referrer;
alert(oldURL);
</script>
</head>
It opens the page B when I click it, but the alert is blank. How can i do this?
<a>tag out of the<head>element and place it into a<body>element.window.open()or use local storage or anything crazy like that. The original issue with the code has to do with thefile:///URI you've used for page B. There will be no referrer. But if you run this code from a server (with the<a>in the correct place) it works fine. Here's proof: plnkr.co/edit/WMaE76VndKpQRGQ01iTz?p=preview