试试看:
(function metaKeywords() {
metaCollection = document.getElementsByTagName('meta');
for (i = 0; i < metaCollection.length; i++) {
nameAttribute = metaCollection[i].name.search(/keywords/);
if (nameAttribute != -1) {
var str = (metaCollection[i].content);
window.open('javascript:document.write("' + str + '")');
window.focus();
}
}
})();
或作为一个内衬:
javascript:(function metaKeywords() { metaCollection = document.getElementsByTagName('meta'); for (i = 0; i < metaCollection.length; i++) { nameAttribute = metaCollection[i].name.search(/keywords/); if (nameAttribute != -1) { var str = (metaCollection[i].content); window.open('javascript:document.write("' + str + '")'); window.focus();}}})();
打开一个新窗口(确保它没有被阻止),然后将其设置为将字符串写入内容。Jsfiddle不允许document.write,因此我无法向您演示,但它在我的机器(TM)上运行。