Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 990287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:55:31+00:00 2026-05-16T05:55:31+00:00

Today i was trying to study about frameset by creating a few pages ,

  • 0

Today i was trying to study about frameset by creating a few pages , this is how the site works , the frameset-defining page is divided into two separate child frame , and inside the two pages contain a textarea and a button that will print out the pages that are visited to the textarea when user click the button,the page is as follow:

The frameset-defining page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<title>Example</title>

<head>

<script type="text/javascript">

var siteList = new Array();

function returnPageVisited_onclick()
{
 var returnValue = "The pages you've visited : " + "\n"

 for(var i = 0 ; i < siteList.length ; i++)
 {
  returnValue += siteList[i] + "\n";
 }
 window.document.myForm.pageVisited.value = returnValue;
}

function printSiteLs_onload(fileNameStart)
{
 var pageName = fileNameStart.lastIndexOf("/") + 1;

 siteList[siteList.length] = fileNameStart.substr(pageName);
}

</script>


</head>



<frameset cols="50% , *">

 <frame src="pageA.html" name="fraLeft" />
 <frame src="pageB.html" name="fraRight" />

</frameset>


</html>

the frame page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<title>Example</title>

<head>
</head>

<body onload="window.parent.printSiteLs_onload(window.location.href);">

<h2> This is Page A </h2>

<p>

<a href="pageA.html">Page A</a>
<a href="pageB.html">Page B</a>
<a href="pageC.html">Page C</a>
<a href="pageD.html">Page D</a>

</p>

<form name="myForm">

<textarea name="pageVisited" rows="10" cols="35">
</textarea>

<input type="button" name="myBtn" value="Click To Check"    onclick="window.parent.returnPageVisited_onclick()"/>

<br />

</form>

</body>

</head>

</html>

There are another 3 pages which are coded the same as the frame page above,just the line <p> This is page A</p> is different , my problem is the line of code in the frameset-defining page ,that is window.document.myForm.pageVisited.value = returnValue; for the first function , firebug gave me an error “window.document.myForm is undefined”,here is how I think,I’m using the frameset to create a module to store generic function so that other pages could access the function in it,but I wonder why I’m getting this error since the function is not called in the mainpage but is called in the frame pages where myForm is defined,so why am I still getting this kind of error,much appreciated if someone could correct my statement if I’m wrong thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:55:32+00:00Added an answer on May 16, 2026 at 5:55 am

    The problem is, even though you are invoking ‘returnPageVisited_onclick()’ from with the frame page, when it runs, it does so in the scope of the frameset defining page. Under these circumstances ‘window’ refers to the frameset defining window, not the frame window.

    What you need to do, to solve this, is to pass the form reference in to the function.

    onclick="window.parent.returnPageVisited_onclick(this.form)"
    

    …and then use that reference directly…

    function returnPageVisited_onclick(targetForm)  
    {  
       var returnValue = "The pages you've visited : " + "\n"  
    
       for(var i = 0 ; i < siteList.length ; i++)  
       {  
         returnValue += siteList[i] + "\n";  
       }  
       targetForm.pageVisited.value = returnValue;  
    }  
    

    Does this make sense?

    UPDATE:

    It looks like further explanation is required…

    It all revolves around a thing called context, which is a point of reference from which all things are accessed.

    To give a massively simplified explanation, imagine that you have 2 PCs with the same web page open on each. A piece of code is run that refers to a variable ‘x’. You wouldn’t expect the code on machine A to access the ‘x’ variable from machine ‘B’, or vice-versa. This is because there is an implied context, and that context is the machine that the code is running on.

    To apply this concept to your example, when you refer to ‘window’, what your are implying is ‘the current window’ – i.e. the window in which the code is located. So, when your frame hosted page says…

    window.parent
    

    …it is explicitly providing a context that is equivalent to the window object of the frameset defining page. When this context is applied to the ‘returnPageVisited_onclick’ call, any references to ‘window.document.myForm’ are in that page, NOT in the frame hosted page. This then fails, as there is no form in the frameset defining page.

    This is why I suggested that you pass the parameter into the function, as this parameter provides a context from which you can refer to the form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got this error today while trying to build a project with checkstyle. This works
I ran into a problem today trying to override an implementation of an interface
I've search all over today trying to find how to do this, and not
I always use preg_match and it always works fine, but today I was trying
Today I am trying to echo this php mysql statement within my javascript code,
I am trying to sort articles by Today, This Week, This Month , All
I ran into a problem today when trying to set a field using FieldInfo.SetValue()
I have spent the better part of today trying to figure this out and
Today I was trying to install Redmine on my shared hosting following this guide:
yesterday I watched Google IO Talk about NFC and today I'm trying to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.