I have a page that was dynamically made using javascript's window.open();
function. This opens a new window with a URL of about:blank
and then I inject the rest of the code into the page. I'm trying to detect whether or not the user refreshes the page and then in a later script tell the opener that the task was completed (hence why this page isn't a static one, it needs to communicate with another open tab)
The problem is, is doesn't seem to be setting the hash on the end of the URL. I'm not even sure if its even possible to do this since it's not an actual URL.
if (document.location.hash=="#one") {
alert('Good Job!')
} else {
document.onunload=function() {
window.location.href = window.location.href+encodeURIComponent("#one");
}
}
I had used encodeURIComponent()
because i had heard somewhere that it was good practice to do so in case of non-alphanumerics. I'm not sure if this is the problem or if I should have used href=#one
but neither seemed to work.
Any solutions?