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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:21:15  来源:igfitidea点击:

how to get <head> content of the current page with jquery or JS

javascriptjqueryhead

提问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

You can give it a try here

你可以在这里试一试

回答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>页面标题...'