I'm creating a static website and I am using iframes. The problem is, when I navigate to another page, say for example, this code for the iframe:
<iframe marginheight="0" align=top src="aboutus1.php" frameborder=0 scrolling=no border=0 WIDTH=800 framespacing=0 id="bodyframeid" name="bodyframename" onLoad="autoResize('bodyframeid');>" ></iframe>
The src
attribute is pointing to aboutsus1.php. Now, when I navigate to another page, for example, I go to aboutus2.php then I reload the page, it goes back to aboutus1.php which is executed by src="aboutus1.php"
. My question is, how do I stay on the current page (aboutus2.php) even if I reload the page?
EDIT: Click here for live example
Click the link above. First page you will see is About CTI
. Now, try clicking on Partners
menu then refresh the page. It goes back to About CTI
page. How do I prevent it from going back to About CTI
page when the page reload?
If you have in your iframe the documents from the same domain (same origin), or you can set the
Access-Control-Allow-Origin
headers on displayed page, you can detect iframe src change, and save the current URL (cookie, localStorage or anything you have), and restore it on page load.You can't. By reloading the page you are loading a completely new page that just happens to come from the same resource as the previous page.
You can't avoid reloading the iframe when you are reloading the main page, but you can make it reload the same page again.
If you want to load a specific page in the iframe, you need to send information to the main page what to put in the iframe
src
. You can for example send that information in a query string, or put it in a cookie.You could store the current page location in a session, and on reload load the url stored in the session. But you'd need some server side technology. In just html you don't store things. You might also be able to use a GET value.