Javascript-I want to use the public header at the bottom of every page on a website.

Source: Internet
Author: User
I want to use the public header at the bottom of each page of a website. How can this problem be achieved. I want to use the public header at the bottom of each page of a website. How can this problem be achieved.

Reply content:

I want to use the public header at the bottom of each page of a website. How can this problem be achieved.

For reference only:

  • Use JS to dynamically request uniform headers and tails, and insert the specified position

  • Backend solution,#include('header.vm')Modify templates in batches, but pay attention to compatibility issues.

  • Server. If nginx is used, enablesub_filterModule

Subs_filter'''Common header JS code 'I;

We recommend that you use the first method. There are always common JS references!

You can use templates. I know jade as the front-end template. You can define the public part as mixin and include it to each required page. For details, refer to here.

In the php backend, you can also define a variable, save the required html as a string in this variable, and then echo it to each page.
Of course, you need to define a parent class first. All requests first use this parent class to process some public logic, such as adding header/footer, and subclass will process more specific logic.

Reconstruction is required.

It mainly depends on the framework you are using. Most frameworks have templates, which can be used to propose public components for reuse.

header
Content
footer

Page 1.html

Include 'header'; Page 1 content include 'footer ';

Page 2.html

Include 'header'; Page 2 content include 'footer ';

Create a header. php and a footer. php file to write the headers and footer content.

Then, on the page to introduce the header and footer


Other content

PHP implementation:

include 'header.html';...include 'footer.html';

JS implementation:

...

《script》 $('#header').load('header.html'); $('#footer').load('footer.html'); 《script》

Yes. After defining the public header file and the final file, you can include it in the main file. As for variables and things, the processing is the same.
Http://document.thinkphp1.cn/manual_3_2.html#template_layout

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.