TLDR打印具有變量的URL
我想打印
<link rel="canonical" href="http://nyc.mymusicwebsite.com/coolband/1222
"/>
其中
var termsText = nyc
var deliurl = http://nyc.mymagazine.com/coolband/122
deliurl2[1] = mymagazine
deliurl[2] = .com/coolband/122
(deliurl在拆分)。 我有這樣的代碼到目前爲止這幾乎奏效,這就是問題
document.write('<link rel=cononical"'+" ""href="http:"//"""+termsText+"."+deliurl2[1]+deliUrl[2]'"/>');
我有一個Drupal網站,致力於爲每一個崗位重複的內容,
每一個崗位創建多頁
http://nyc.mymusicwebsite.com/coolband/1222
http://national.mymusicwebsite.com/coolband/1222
http://seatle.mymusicwebsite.com/coolband/1222
http://la.mymusicwebsite.com/coolband/1222
雖然只有一個職位是該網站的其他職位獲得索引上可見。
上面的帖子都標記在一個div與他們分配的區域,並在網站上可見。
我想打印google rel conical鏈接,鏈接到conincal post。這篇文章的子域與div中的pages標籤相同。
我所做的一切,除了打印網址
考慮下面的代碼
//find tag in page for pattern match
var termsText = $("#terms").find("ul li:last").text();
//get window location url to test agains pattern
var deliUrl=window.location.href
//test pattern
var patt1=new RegExp(termsText);
//split url at first period to isolate everything after the subdomain
var deliUrl2=deliUrl.split('.');
//if pattern is NOT in url print google conical tag pointing to propper subdomain
if (patt1.test(deliUrl));
{
//print subdomain as "terms" and rest of url
document.write('<link rel=cononical"'+" ""href="+termsText+"."+deliurl2[1]+deliUrl[2]'"/>');
}
你能解釋一下爲什麼你要這樣做嗎?我覺得你錯過了森林,但樹木。 – mrtsherman
我們有3位程序員正在處理這個問題,現在我們只需要一個子域(在帖子內容中具有匹配標籤的子域)進行索引。這已經委託給我了。 –
我只需要幫助我的document.write()語句的語法我是新來的JavaScript和語法是一個弱點 –