0

I want to stay with my current page, but everytime I refresh the iframe go back to it's default page url src="app.php" . For example I'm on pr.php, and I accidentally refresh the page, I want to stay with that page. If it possible?

<a href="app.php" target="contents">APP</a><br/>
<a href="rfq.php" target="contents">RFQ</a><br/>
<a href="pr.php" target="contents">PR</a><br/>
<a href="addapp.php" target="name" onclick="modalWin(); return false;">Add APP</a><br/>
<a href="livesearch/index.php" target="contents">SEARCH</a><br/>
 <iframe name="contents" src="app.php" frameborder="0" id="iframe" 
 frameborder="0" style="moz-overflow:hidden;moz-overflow-x:hidden;moz-overflow-y:hidden;height:100%;width:100%;position:absolute;top:0px;left:0px;right:0px;bottom:0px" height="100%" width="100%"> </iframe>
asked Nov 26, 2013 at 6:12
0

1 Answer 1

1

You can use the html5 localStorage to save your iframe's current url, and you refresh the page try to load it, if it is undefined try to load the initial page. Your iframe must not have src attribute at its tag declaration, you will set it with jquery. I've done an approximation of what youu may want, I hope it works

$(document).ready(function() {
 currentLocation = localStorage.prevUrl || 'yourInitialSrc';
 $('#iframe').attr('src', currentLocation);
 $('#iframe').load(function() {
 localStorage.prevUrl = $(this)[0].contentWindow.location.href;
 })
})

iframe load event is triggered when your iframe loads a page. So in your iframe if you go to another link the load event is triggered and you save locally in your browser the url you are now.

But please try to avoid iframes at any cost. And watch out how you operate the local storage...

answered Nov 26, 2013 at 7:42
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.