简体   繁体   中英

Include separate HTML which includes code in the <head>

I have a bunch of link tags in the tag of my HTML document. Is there any way I can put all of this in a separate HTML document and just link to that one?

Eg turn this:

</head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href='http://fonts.googleapis.com/css?family=Arvo:700' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" type="text/css" href="styles.css">
    <script src="scripts.js"></script>
    <title>Home</title>
</head>

Into this:

<head>
    <link href="head.html" type="text/html">
    <title>Home</title>
</head>

With the separate file head.html containing all those links?

You can include all your stylesheets in one stylesheet with the include method like follows:

CSS:

include 'http://fonts.googleapis.com/css?family=Arvo:700'
include 'http://fonts.googleapis.com/css?family=Lato:300'
include 'http://fonts.googleapis.com/css?family=Roboto:300'

and then link just the main CSS file.

The short answer is frames. That is if you want to use 'html' only. Yet frames are bad practice tbh, specially for this.

You can do the 'include' with Jquery too:

<script> 
$(function(){
  $("#yourdiv").load("includefile.html"); 
});
</script> 

An other way is to include with PHP

http://php.net/manual/en/function.include.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM