Javascript 如何使用jquery或JS获取当前页面的<head>内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3592475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to get <head> content of the current page with jquery or JS
提问by faressoft
how to get <head>content of the current page
如何获取<head>当前页面的内容
回答by user113716
You could use the javascript DOM API like this:
您可以像这样使用 javascript DOM API:
var headContent = document.getElementsByTagName('head')[0].innerHTML;
回答by Nick Craver
You can use an element selectorto get <head>, for example:
您可以使用元素选择器来获取<head>,例如:
$("head")
//for example:
alert($("head").html()); //alerts the <head> children
回答by egoproxy
Simply as:
简单来说:
document.head
document.head
// returns object DOM Object
// 返回对象 DOM 对象
document.head.innerHTML
document.head.innerHTML
// returns text, like: '<title>Title of the page...'
// 返回文本,如:'<title>页面标题...'

