JavaScript tips for allowing Web pages to automatically put on coats

Source: Internet
Author: User
Javascript| Skills | Web page

When you are designing a Web page, many pages need the same border pattern and navigation bar, FrontPage provides us with a shared border to facilitate the design, but this is not too convenient, after all, each page has added the same content, virtually the page increased, of course, for dynamic Web pages, this is not a problem, but, What if it's static?

When you are designing a Web page, many pages need the same border pattern and navigation bar, FrontPage provides us with a shared border to facilitate the design, but this is not too convenient, after all, each page has added the same content, virtually the page increased, of course, for dynamic Web pages, this is not a problem, but, What if it's static?

How to overcome this shortcoming, through the framework can achieve these, just, the framework has attracted another trouble, is if the direct opening of the framework inside the Web page, take off the gorgeous coat, is not very monotonous, here we find a good way, let off the coat of the Web page automatically put on the coat, you think of it? If you are not interested in this issue, you can go away, let's discuss it in detail below.

In a frames page, the src parameter is usually used to specify the page address in the frame, and what we do is, when we open the address directly, let it automatically monitor and then put on the coat, of course, first add the detection code to the page, as follows:

<script>
if (top.location==self.location)
{
Top.location= "Index.htm?" +self.location;
}
</script>

It's so simple, notice, index.htm is the coat page address, the next thing to do is, how to let the coat page automatically add this part of the content, we want to resolve the page in the Jacket page address, find parameters, and then the frame src parameters to the argument on the line, the code is as follows:

<script>
document.write (' <iframe id= "mid" name= "mid" width= "100%" height= "100%" frameborder= "0" scrolling= "Auto")
var n=self.location.href.indexof ("?") See if parameters are included
if (n>0)//exists parameter
{
Point to Parameters
document.write ("src=" +self.location.href.substr (n+1))
}
document.write (' ></iframe> ')
</script>

The IFRAME framework is used here, and the specific application can be seen on my website ggg82.126.com.

You can click here to see the effect, if you do not understand the place, you can contact me. Have any good views, welcome to discuss with me.



Related Article

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.