views:

47

answers:

2

Hi, I am trying to create an embedded <script> containing a function called "showForm()" that displays the contents of a file called "form.htm" within the main browswer window.

This is what I need to do:

  1. Display the form.htm file in the browser window that was used to open the cover.htm file. (hint: use the "opener" keyword to reference the main browser window, and the location.href property to specify the document to be displayed in that window.)

  2. Close the current window.

I am having a hard time figuring out exactly what each part is and what it all means and I also don't really understand how to write it. I get that I am trying to open new content("form.htm") within the existing browser window "cwj.htm" and then close it out but I don't understand how to write it. Any help is appreciated. Thanks!

Here is the code I have come up with. See the <script> tag:

 <head>
   <title>Subscription</title>

<link href="cover.css" rel="stylesheet" type="text/css" />


<script type="text/javascript">
    function showForm() {
    <!--window.open("form.htm","opener","");
        window.close(); -->
        <!--window.open("location.href"); -->
        document.write(location.href);
        window.open("form.htm","opener","");
        window.close();
    }
</script>
</head>
A: 

I think they mean window.opener not "opener". window.opener is a reference to the window which opened the current window.

nickf
A: 

A couple of things:

Your script block should look like this:

<script type="text/javascript">
<!--
   your code goes here
//-->
</script>

You can actually just use:

<script>
  your code goes here
</script>

and it will work in all modern web browsers; but you'll probably want to include the HTML comment markers <!-- //--> for completeness.

Inside the script block, you shouldn't use HTML comments <!-- --> to disable your code. You'll want to use C-style comments /* disabled code goes here */

Now on to your code. You define a function:

function showForm() {
}

this defines a function in your code that can run, but it won't run until you call it, like this:

showForm();

Javascript happens more or less instantly, so if you open a window, then immediately close it again, you probably won't see it. Try just getting it to open, first.

window.opener is a global property within a window which was opened as a popup. It points to the window object of the other window which opened the popup.

I hope this gives you enough help to figure it out without doing your homework for you. =)

RMorrisey