0

I want to embed some third party content which will be an html page, inside my html website. I thought of using the iframe approach in which i will embed the third party html page inside my website as an iframe.

The motivation behind using iframes was that i dont know what libraries they might use, or what CSS they might write. I wanted their logic to be separate from mine. Iframe fulfills my this wish.

But now i have a problem, if i want the browser Back/Next Functionality for any navigation's inside the iframe, it will be very difficult to maintain because of the route. At the same time, maintaining the iframe state when the parent page is refreshed will be pretty tough.

So, is the iframe approach fine first of all? If it is, then how do i cater to the Browser Back/Next?

gauravmuk
  • 1,606
  • 14
  • 20
  • isn't the above topic related to having a back button inside iframe? i want my functionality to work from browser back/next and the topic doesn't help me with the page getting refreshed scenario. – gauravmuk Feb 17 '14 at 07:56
  • _“At the same time, maintaining the iframe state when the parent page is refreshed will be pretty tough”_ – correct. It _can_ be done though, but it will require both pages to _work together_: Using `window.postMessage`, two pages can communicate even across domain barriers; so the iframe would have to tell the parent page what actual address it is currently displaying whenever a change occurs – that way, the parent page can create the iframe element with the “right” address loaded from the beginning when it is reloaded. […] – CBroe Feb 17 '14 at 08:07
  • [Contd.] Any navigation history within the iframe will still get lost on reload of the parent however – since it will be a “new” iframe each time. – CBroe Feb 17 '14 at 08:08

1 Answers1

0

Well, you can manage back/forward button with JavaScript like this:

iframe.contentWindow.history.back(); 
iframe.contentWindow.history.forward();

Bigger problem is that included page can disallow possibility to be included into iframe (if you include page with this behaviour into iframe, it will load over your page - check for example this qeustion).

Community
  • 1
  • 1
Pavel Štěrba
  • 2,822
  • 2
  • 28
  • 50