Javascript Window Function guide-named window and framework

Source: Internet
Author: User
When you create a framework structure document, the name attribute of the <frame> tag defines the name of each framework, as follows:

<Frameset>

<Frame name = "Left" src = "toolbar.html">

<Frame name = "right" src = "index.html">

</Frameset>

In this example, the document contains two frameworks: left and right. In the document toolbar.html, the link code is as follows:

<A href = "about.html" target = "right"> about us </a>

<A href = "feedback.html" target = "right"> feedback </a>

Note: The <form> tag also supports the target attribute, which defines the target window of the Response Form. The <BAEE> MARK specifies the general default target window for all links in the document:

<Base target = "right">

The above tag defines the target location of all elements on the page. The following HTML elements support target attributes: <A>, <area>, and <form>.

In practical applications, the <base> element must appear between the head mark of the document before any element pointing to an external resource. If the <base> flag is specified in the document, the link will not follow the default target location, but will be explicitly directed to another different target location:

<Head>

<Base target = "right">

</Head>

<Body>

<A href = "table.html" target = "_ Self"> table of contents </a>

<A href = "about.html"> about us </a>

<A href = "feedback.html"> feedback </a>

</Body>

As shown above, the target of the 1st links is "_ Self" (with an underline), which means that when you click this link, the new document will open in the current activity window. The following table lists some special target location identifiers in HTML:

Target Description
_ Blank Load the document in a new empty window. The new window is not named.
_ Parent Load the document in the parent window of the link.
_ Search Load the document in the browser's search area. Note that this function is only applicable to Internet Explorer 5 or later.
_ Self Load the document in the window where the link is located.
_ Top Load the document in the top window.

Now that we understand the framework name, we will work with the window below. When the target is defined as "_ blank", a new window will pop up. For example, to open a link in a new window, use the following code:

<A href = "newpage.html" target = "_ blank"> A new page </a>

The new window is not named. In other words, it cannot be referenced by the target attribute of other elements. But what happens when we use a standard target name? See the following definition:

<A href = "newtip.html" target = "tip"> A new tip </a>

In this case, we provide a special name for the new window. The name of the new window is "tip", so any link or form that defines target = "tip" loads the page in the same window. If no frame or window matches the specified target, click the link to open it in the new window. Take a look at the following example:

<A href = "http://www.ccidnet.com/" target = "_ blank"> ccidnet </a>

<A href = "http://www.ccidnet.com/tech/" target = "_ blank"> technology world </a>

Let's take a look at the results:

Ccidnet, Technology world
Click the first link to open the document in a new window. Click the second link to create a new window. If you click the link again, the new window will still open. As you can see, each time a link is clicked, a new window is generated. Let's try the following example again:

<A href = "http://www.ccidnet.com/" target = "Main"> ccidnet </a>

<A href = "http://www.ccidnet.com/tech/" target = "Main"> technology world </a>

The effect is as follows:

Ccidnet, Technology world
When you click the first link, a new window is generated. Click the second link, and the new document will appear in the window that just opened. The new window is named "Main", so any link or form with target = "Main" specified will be loaded in that window.

Name attributes
With JavaScript, we can find the window name (for ie3 +, n2 +) through the window name attribute ). Similarly, we can set the name attribute of a framework or window (applicable to ie3 +, N3 + ). Let's take a look at the following HTML document (showname.html ):

<HTML>

<Head> <title> display name </title>

<Body>

<Script language = "JavaScript">

<! --

Alert ('the name of this window is: "'+ window. Name + '"');

// -->

</SCRIPT>

</Body>

</Html>

Let's look at the following link:

<A href = "showname.html" target = "_ blank"> a new window </a>

<A href = "showname.html" target = "first"> first window </a>

<A href = "showname.html" target = "second"> second window </a>

<A href = "showname.html" target = "third"> third window </a>

The document showname.html contains a script program that displays the name of the window in an alert dialog box.

The name attribute belongs to the window object. It can be used by any window object, including the framework. For example, the following statement sets the name of a framework window:

Parent. Frames [1]. Name = "right ";

When operating the framework, it is very easy to access windows at different layers. For more details, visit window references.

HTML cannot assign a name to the current window. That is to say, it is impossible to set the name of the current window through HTML code on the current page. To achieve this goal, only one method is to assign a value to the window. Name attribute. Let's try the following code. It creates a simple button and click it to set the name of the current window:

<Form>

<Input type = "button" value = "Set Name To mywin" onclick = "window. Name = 'mywin'">

</Form>

After you click the button, the name of the current window will be changed to "mywin", unless other values are assigned, it will remain. We can include links in other windows and define their target location as mywin, that is, target = "mywin ".

If you have set the name of the current window as mywin, the link will open in the current window. The code in the new window is as follows:

<A href = "http://www.docjs.com/" target = "mywin"> Home </a>

<A href = "http://www.docjs.com/tips/" target = "mywin"> recent tips </a>

For convenience, we provide the source code of the button that can set the name of the current window to null:

<Form>

<Input onclick = "window. Name ='' "type = button value =" Reset name "name =" button2 ">

</Form>

Do not assign the same name to two different windows. If two windows are assigned the same name, only one window is associated and the other is ignored.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.