<link rel="import" href="header.html">
<link rel="import" href="footer.html">
<script>
var link = document.querySelector('link[href*="header"]');
var template = link.import.querySelector('template');
var clone = document.importNode(template.content, true);
document.querySelector('#nav').appendChild(clone);
</script>
<script>
var link = document.querySelector('link[href*="footer"]');
var template = link.import.querySelector('template');
var clone = document.importNode(template.content, true);
document.querySelector('.footer').appendChild(clone);
</script>
回答
除Chrome之外沒有其他瀏覽器已發貨<link rel=import>
HTML導入支持。 Firefox不支持HTML進口unless you enable the dom.webcomponents.enabled
flag:
Firefox will not ship HTML Imports. See this Hacks blog post for more information. You can still use HTML Imports in Firefox by enabling the dom.webcomponents.enabled flag. If you don't want to enable the flag, you can use a polyfill such as Google's webcomponents.js.
目前HTML Imports spec基本上是死在這一點上,由於2016年2月在剛工作草案狀態停滯不前,而不會沿着W3C標準化的軌道進一步推動所有。
所以沒有其他瀏覽器會實現這個舊的HTML Imports規範。相反在某些時候,將會開發一個新的規格 - 一個掛鉤到ES6 Modules和<script type=module>
「module scripts」 as now defined in the HTML spec的基礎機器。
我會建議使用文件HTML-imports.min.js從HTML Imports polyfill毋寧說是不是在用戶的瀏覽器中啓用,其實施已過期(和Firefox的標誌可能會導致與其他polyfills conficts自定義元素或陰影DOM)。
此外,使用polyfill時,請記住HTML導入將始終爲async
,因此在使用link.import
屬性的內容之前,您必須等待HTMLImportsLoaded
事件。
<script src="html-imports.min.js"></script>
<link rel="import" href="header.html">
<link rel="import" href="footer.html">
<script>
document.addEventListener('HTMLImportsLoaded', function()
{
var link = document.querySelector('link[href*="header"]');
var template = link.import.querySelector('template');
var clone = document.importNode(template.content, true);
document.querySelector('#nav').appendChild(clone);
link = document.querySelector('link[href*="footer"]');
template = link.import.querySelector('template');
clone = document.importNode(template.content, true);
document.querySelector('.footer').appendChild(clone);
})
</script>
- 1. 仍然得到錯誤空數組
- 2. SplitViewTemplate,所以我得到的錯誤是不以命名空間
- 3. 得到錯誤
- 4. 錯誤得到
- 5. 得到錯誤
- 6. 得到錯誤
- 7. 得到錯誤
- 8. 在輸入數據到mysql得到連接空錯誤
- 9. 得到錯誤,而在Ubuntu
- 10. 得到錯誤在迅速
- 11. 得到錯誤在angular4
- 12. 得到錯誤在IIS
- 13. 得到錯誤,而在PHP
- 14. 得到錯誤,而在Python
- 15. 得到一個錯誤,可能是WebResource.axd
- 16. curl php總是得到錯誤403
- 17. 得到錯誤:appium&commnad不是MAC
- 18. 我得到錯誤:值EXEC不是io.gatling.http.request.builder.HttpRequestBuilder
- 19. 得到indexOutOfRangeException是未處理的錯誤
- 20. 我總是得到錯誤代碼2000
- 21. Ajax調用總是得到錯誤塊
- 22. Symfony的3 - 總是得到404錯誤
- 23. 得到錯誤org.springframework.web.context.ContextLoaderListener
- 24. 我得到的錯誤「應用程序」是在命名空間「的Microsoft.Office.Interop.Excel」
- 25. Firefox CSS錯誤
- 26. Firefox javascript錯誤
- 27. Firefox「ssl_error_no_cypher_overlap」錯誤
- 28. FireFox webdriver錯誤
- 29. 我得到「mysqli_query():空查詢」錯誤,並找不到錯誤的行
- 30. 我得到錯誤,當我使用fgets而不是得到
Chrome ...和它的表兄歌劇和Ionic /科爾多瓦 – Supersharp
是的,是的 - 謝謝你指出。我想我應該只是「基於閃爍的瀏覽器」... – sideshowbarker