JLYK
JLYK

Reputation: 391

how to remember which href your iframe is pointing to upon browser refresh?

So I have a webpage that contains an iframe that changes to different pages depending on what the user clicks in the menu bar. Everything works fine except I don't like it when I click "refresh" on the browser and it forgets which page I'm on and it reloads the default page. How do I get it to remember which page I was browser at?

<ul>
    <li><a id="HyperLink1" runat="server" href="Page1.aspx" target='contentframe'>Page1</a></li>
    <li><a id="HyperLink2" runat="server" href="Page2.aspx" target='contentframe'>Page2</a></li>
    ...
</ul>

<div id="content">
    <iframe name='contentframe' src='Page1.aspx'></iframe>
</div>

Upvotes: 1

Views: 273

Answers (2)

Alexander Schranz
Alexander Schranz

Reputation: 2450

There are 2 ways

you go over Server Site Session (only now how to do this in PHP not in ASPX) or you go over a Javascript Cookie

Javascript

use jQuery with Cookie plugin to set a cookie

  1. set in Page1, Page2 the Cookie

    $.cookie('page', 'page1.aspx'); // for page 2

  2. on your site you read the cookie and set the src of the iframe from the cookie

    $('#iframeID').src($(.cookie('page'));

But JS is not a good solution for this if possible use a server site session variable.

Upvotes: 2

carter
carter

Reputation: 5432

localstorage.iframeurl = 'URL';

Upvotes: 0

Related Questions