<link rel="import" href="">
1、使用link标签导入
2、link标签的rel属性值为import
3、link标签的href属性值为需要导入的资源
<!DOCTYPE html> <html> <head> <title>Demo</title> <link rel="import" href="imports/myimport.html"> </head> <body> <p>This is a import demo</p> </body> </html>
import关键字给资源提供的默认类型是text/html
该link标签还有一个async属性,其值为布尔类型
该link标签不依赖media属性(media属性不生效)
可以在JavaScript中获取到import的属性,如
var link = document.querySelector('link[rel=import]'); var heart = link.import; var pulse = heart.querySelector('div.pulse');
返回的import为被引入的文档的document对象。
如果通过JavaScript脚本创建link import标签,可以通过onload或onerror事件监听其是否加载成功或失败,如
var link = document.createElement('link'); link.rel = 'import'; link.href = 'myimport.html'; document.head.appendChild(link); alert(link.import) // null,因为import的内容是异步载入,需要通过下面的onload来处理 link.onload = function(){}; link.onerror = function(){};
虽然,返回的import为document对象,但导入的document不能使用document.open(),document.write(),document.close()方法,使用这些方法会抛出InvalidStateError异常。
由于是document对象,可以使用document.head.innerHTML;document.body.innerHTML;document.querySelector()
被导入的html文档中也隐含着head和body,其中导入其它文档(如果有的话)的link标签会出现在document.head中,其余的会出现在document.body中。
在被导入的html文档中的document指的是主文档的document;
在被导入的html文档中,可以通过document.currentScript.ownerDocument来获取当前(即被导入文档自身)的document
将被导入html文档的内容加到主文档的示例:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Demo</title> <link rel="import" href="imports/myimport.html"> </head> <body> <script> var link = document.querySelector('link[rel="import"]'); document.body.appendChild(link.import.body.querySelector('p').cloneNode(true)); </script> </body> </html>
浏览器的网络协议栈(network stack)会对访问相同URL的请求自动去重。这意味着从同一个URL导入的内容只会被获取一次。无论这个地址被导入多少次,最终它将只执行一次。
特性检测:
function supportImports() { return 'import' in document.createElement('link'); }
相关推荐
HTML导入SHIM NB HTML Import SHIM最初由filament group的Scott Jehl于2019年4月出色地记录在: 的HTML导入SHIM(šimpleħTML我M端口中号ethod)是一个客户端技术,该技术使得Web文档引入外部HTML文件(和文件片段...
python调试文件时发生import requests报错,先填写环境变量,如何一步步完成pip安装过程。
You can import data from MS Excel, MS Access, DBF, XML, TXT, CSV, ODF and HTML. There will be no need to waste your time on tiresome data conversion - Advanced Data Import will do the task quickly, ...
Data import from the most popular data formats: MS Excel 97-2007, MS Access, DBF, XML, TXT, CSV, OpenDocument format (ODS, ODT), and HTML Import of Unicode data (UTF-8, UTF-16/UCS-2, UTF-32/UCS-4). ...
import android.text.Html; TextView t3 = (TextView) findViewById(R.id.text3); t3.setText( Html.fromHtml( "<b>text3:</b> Text with a " + "<a href=\"http://www.google.com\">link</a> " + "created in...
html-import> 用于将HTML文档(或文档的一部分)导入其他文档的自定义元素。 如果您了解PHP,则基本上是客户端include() 。 <!-- The complete file (body) content will be appended after the ...
beautiful soup库的引⽤ 库的引⽤ from bs4 import BeautifulSoup import bs4 BeautifulSoup类 类 BeautifulSoup对应⼀个HTML/XML⽂档的全部内容 回顾 回顾demo.html import requests r = requests.get("ht
import doc from './my-html-module.html' as HTMLModule ; 这可以完全替代HTML导入,从而利用JavaScript模块系统,而不是具有用于导入的并行依赖项系统。 此外,这允许将HTML模块的整个实现编写在JavaScript库中...
import random.html
TRichView Delphi Component包的开源HTML导入模块。
TQImport3HTML Intended for importing tables from HTML pages TQImport3XMLDoc Import data from generic XML files using XPath and DataLocation (tlAttributes, tlSubNodes) TQImport3XLSx Intended for ...
from xlsx2html import xlsx2html out_stream = xlsx2html ( 'path/to/example.xlsx' ) out_stream . seek ( 0 ) print ( out_stream . read ()) 或传递文件路径 from xlsx2html import xlsx2html xlsx2html ( '...
babel-plugin-transform-html-import-to-string 将HTML导入转换为字符串。 例子 给定以下example.html 。 < h1> Hello 在 import html from './example.html' ; 出去 var html = '<h1>Hello</h1>' ; 安装 $ npm ...
:return: 网页html数据(文本格式) ''' headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' } url = '...
You can import data from MS Excel, MS Access, DBF, XML, TXT, CSV, ODF and HTML. There will be no need to waste your time on tiresome data conversion - Advanced Data Import will do the task quickly, ...
from w3lib.html import remove_tags def extract_num(text): #从字符串中提取出数字 match_re = re.match(".*?(\d+).*", text) if match_re: nums = int(match_re.group(1)) else: nums = 0 return nums ...
Import as Android Studio project. Run the bootstrap script from terminal via scripts/bootstrap.sh. This will install the Google Java code style as well as the official Android Kotlin code style and ...
import-html.js 适用于不了解使用HTML导入功能的框架的前端初学者。 用其他语言阅读:,。 用法 用HTML加载脚本: <body> ... <!-- place before the end of body tag is suggested --> [removed]...
import-html-entry 将索引html视为清单,并加载资产(css,js),从入口脚本获取导出。 <!-- subApp/index.html --> <!DOCTYPE html > < html lang =" en " > < head > < meta charset =...
import-html-entry 将索引html视为清单,并加载资产(css,js),从入口脚本获取导出。 <!-- subApp/index.html --><!DOCTYPE html >< html lang =" en " >< head > < meta charset =" UTF-...