Friday, February 22, 2008

iframes and history

Iframes implements history on their own. They are not necessarily realted to the window history. Accessing that history creates a problem when the window and frames belong to different domains. The familiar "Access denied" or "permission denied" pops up on the IE. IE also doesn't allow access to the properties of location object. So parent frame is not allowed to know the location details of the child frame. Now if the parent doesn't know the location details of the child, how can it reload the child frame. Now reloading a child frame by parent frame is no security violation and is allowed in case of Mozilla. I wouldn't let IE take credit for more security because it is plain baseless. When a page is allowed to open a page in its iframe, why isn't it allowed to reload it or make it move back or forward!
Problem: Open a page in iframe, navigate through its links, reload the last page that was visible Possible approaches: in iframe.window.reload causes the whole page to reload, window.history.go(0) too does that. iframe.src="dummy page" --> window.history.go(-1); loads the page from the cache and not the server. iframe.src="javascript" - doesn't work for cross domain pages.
To bypass this problem, I created 3 tier structure: window --> frame1 --> frame 2
frame 1 is local to window and frame 2 loads a different domain. Now the user navigates in the frame 2 using its links, and reaches a page he wants to be reloaded again. Now if there is a button on the window which refreshes the frame 1 (possible since its local to window), the frame 2 refreshes to the last page in it and not the one defined in the src attribute off rame 2.
Quite a feat for me as i could not find this approach even on extensive searching on net.

No comments: