0

i'm using iframe for visit my website some page. What i'm facing now if i visit 2 pages inside of iframe, after refresh the whole page iframe coming to 1st page.

i want to stay in same page when page will reload.

<iframe src="https://my-domain.com/pagelink" name="iframe_a" style="width:100%; height:200px;" title="Iframe" id="frame"></iframe>

Atiq Rev
  • 23
  • 5

1 Answers1

1

<iframe> doesnt have to remember your navigation. So you should do it yourself. After a navigation in the iframe you should remember its location.href somewhere and then restore after the page reload.

There's a recipe how to intercept location.href changes:
Event when window.location.href changes

Good candidates for storing the new location.href are sessionStorage and locationStorage.

But the best way I think it's to utilize some kind of router/routing with history.pushState() so your whole URL for your top page is updated. That way your iframe's href is serialized inside the page's url. You can share the url and the iframe will navigate to the href remembered (serialized) in the page's url (shared and navigated).

Alexander Nenashev
  • 8,775
  • 2
  • 6
  • 17