I find it impossible to do this without using a framework, but I have a solution that can (partially) solve this problem.
First, I was thinking about changing the history object and overriding it, but this is not possible, since this property inside the window is not writable . but we can override functions inside history .
This led me to redefine the back() function, and instead of letting the history object do its job, we should find the previous URL and change the location of the document (child).
In Child.html override the back() function as follows:
history.back = function () { document.location = document.referrer; }
The problem we have in this function is that after loading the parent document and loading iframe (child), document.referrer child object returns the URL of the parent
So, before changing document.location , let the test if document.referrer is different from the original URL (witout anchor)
history.back = function () { var url = window.parent.document.location.href.split("#")[0]; if(document.referrer!=url) document.location = document.referrer; }
Finally, this solution, which I found and unfortunately has a problem, is that you cannot override the forward() function, which allows you to go to the next URL, it is impossible to find the next URL and document.referrer returns The URL of the page you came from can be the previous page or the next page. but still you can navigate inside the iframe without changing the parent location.
Khalid
source share