0

我的网站有一个如下所示的 URL:http: //mysite.co/twittercard.html#johnsmith

我需要抓取#URL 中 hash() 之后的文本,并在meta tag.

我一直在尝试将文本插入meta tag如下:

<html>
<head>
<meta name="twitter:card" content="app" />
document.write('<meta name="twitter:description" content="' + window.location.hash + ' test sentence goes here!" />');
<meta name="twitter:app:country" content="US" />
<meta name="twitter:app:name:iphone" content="App name" />
<meta name="twitter:app:swift:name" content="App name" />
<meta name="twitter:app:id:iphone" content="id0923804893204" />
<meta name="twitter:app:url:iphone" content="testscheme://action/982y9hf92f92" />
<meta name="twitter:app:name:ipad" content="App name" />
<meta name="twitter:app:id:ipad" content="id0923804893204" />
<meta name="twitter:app:url:ipad" content="testscheme://action/892ruhf92hf9" />
</head>
</html>

我什至尝试使用额外的javascript变量,而不仅仅是使用window.location.hash

<html>
<head>
<meta name="twitter:card" content="app" />
document.write('<meta name="twitter:description" content="' + username + ' test sentence goes here!" />');
<meta name="twitter:app:country" content="US" />
<meta name="twitter:app:name:iphone" content="App name" />
<meta name="twitter:app:swift:name" content="App name" />
<meta name="twitter:app:id:iphone" content="id0923804893204" />
<meta name="twitter:app:url:iphone" content="testscheme://action/982y9hf92f92" />
<meta name="twitter:app:name:ipad" content="App name" />
<meta name="twitter:app:id:ipad" content="id0923804893204" />
<meta name="twitter:app:url:ipad" content="testscheme://action/892ruhf92hf9" />
</head>
var username = window.location.hash
</html>

但这也行不通。每当我对此进行测试时,向用户显示的文本都是"'+username+' test sentence goes here!""'+window.location.hash+' test sentence goes here!"

如果我的 URL 是http://mysite.co/twittercard.html#johnsmith,那么我需要将句子显示为:"johnsmith test sentence goes here!"

编辑:

我已经添加了脚本标签,但它仍然无法正常工作:

<html>
<head>
<meta name="twitter:card" content="app" />
<script>
document.write('<meta name="twitter:description" content="' + window.location.hash + ' test sentence goes here!" />');
</script>
<meta name="twitter:app:country" content="US" />
<meta name="twitter:app:name:iphone" content="App name" />
<meta name="twitter:app:swift:name" content="App name" />
<meta name="twitter:app:id:iphone" content="id0923804893204" />
<meta name="twitter:app:url:iphone" content="testscheme://action/982y9hf92f92" />
<meta name="twitter:app:name:ipad" content="App name" />
<meta name="twitter:app:id:ipad" content="id0923804893204" />
<meta name="twitter:app:url:ipad" content="testscheme://action/892ruhf92hf9" />
</head>
</html>
4

0 回答 0