I have been playing around with the history.length property in JavaScript and have come across a bit of a problem I don't understand.

On my localhost machine I have two pages - Page A and Page B that both have one line of script being:

document.write("Number of URLs in history list: " + history.length);

When I load new browser tab and open page A the page says I have 1 URL in history. I then open page B in the same tab and it says I now have 2 URLs in history list. Thats fine.

However, I then tried using iframes. I created an iframe with src to Page A and then changed the src of the same frame to Page B. The problem is instead of returning value of 2 (i.e. Page A and Page B) it says only 1 URL in history list but I opened two pages in the same iframe?

    <iframe src='/pageA.php' id='myframe' onload='checkHistory()' ></iframe>
<script language="javascript" type="text/javascript" >
    function checkHistory() 
            alert("Number of URLs in history list: " + history.length);

Does the history.lenght property have to be accessed differently for the iframe history something like document.getElementById('myframe').history.lenght ?

Any ideas appreciated?

5 Years
Discussion Span
Last Post by fobos

try puting this in pageb.php

function history(){

<body onload="history()">

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.