JavaScript 在頁面中有兩種常見方式。一種是把 JS 做成外部檔案、由頁面直接調用,例如:
<script language="JavaScript" src="https://www.seotest.cn/script/common.js" type="text/javascript"></script>
另一種是在頁面裡直接寫上 JS 代碼,例如:
<script language="JavaScript">
try{
var elScript = document.createElement("script");
elScript.setAttribute("language", "JavaScript");
elScript.setAttribute("src", "https://www.seotest.cn/function/c_html_js.asp?act=batch"+"view="+ escape(strBatchView)+"&inculde="+ escape(strBatchInculde)+"&count="+ escape(strBatchCount));
document.getElementsByTagName("body")[0].appendChild(elScript);
}
catch(e){};
</script>
從搜尋引擎抓取的角度來說,第一種不包含任何文字資訊,搜尋引擎自然無法從中提煉內容。但第二種如果出現了文字內容,搜尋引擎是否能抓取其中的內容呢?
實驗思路:製作一個只有 JS 代碼的頁面,代碼內包含中文內容,然後等待搜尋引擎收錄後,在搜尋結果頁與網頁快照中查看結果。
實驗頁面:(https://www.seotest.cn/testpage/tp009.html)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>2007-9-25 中秋節開始的實驗</title>
</head>
<body>
<SCRIPT type="text/javascript">
document.writeln("JS抓取實驗:<br>");
document.writeln("試試放在JS代碼裡的文字,是否會被搜尋引擎抓取到呢?");
</SCRIPT>
</body>
</html>
如果你希望盡快看到實驗結果,歡迎轉載本文或為實驗頁面增加外部連結,這樣能幫助搜尋引擎更快收錄該頁面,我們也能更快取得結果。
原文鏈接:https://www.seotest.cn/blog/javascript-shoulu-shiyan.html