JavaScript tips: Enable the web page to automatically wear a coat

Source: Internet
Author: User

When designing a webpage, many webpages need the same border pattern and navigation bar. FrontPage provides us with a shared border for Convenient Design. However, this is not convenient, after all, the same content is added to each webpage, And the webpage increases virtually. Of course, this is not a problem for dynamic webpages. But what if it is static?

How can we overcome this shortcoming and implement this through the framework? However, the framework brings another headache: If you open the internal webpage of the framework directly and take off the gorgeous coat, is it very monotonous? Here we are looking for a good way to let the webpage with its coat off automatically put on the coat. Have you thought of it? If you are not interested in this topic, you can leave. We will discuss it in detail below.

In a framework webpage, the src parameter is usually used to specify the webpage address in the framework. What we need to do is, when the URL is opened directly, let it automatically monitor and then put on the coat. Of course, first, add the detection code on the webpage, as shown below:


<Script>
If (top. location = self. location)
{
Top. location = "index.htm? "+ Self. location;
}
</Script>
 


Simply put, index.htm is the coat webpage address. The next thing we need to do is to let the coat webpage automatically add this part of content. We need to parse the webpage address in the coat webpage and find the parameters, then point the framework src parameter to this parameter. 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 ("? ") // Check whether the parameter is included
If (n> 0) // parameters exist
{
// Point to a parameter
Document. write ("src =" + self. location. href. substr (n + 1 ))
}
Document. write (> </iframe>)
</Script>
 


 

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.