點擊鏈接時我需要改變一部分url。點擊鏈接時用jQuery改變網址
$('.slavearticle a.headlinelink').click(function() {
var url = $(this).attr('href');
url = url.replace('/something.example.com', 'betterexample.no');
console.log(url);
return false;
});
期望在這裏都將是如果該URL是something.example.com/index.html將它更改後到betterexample.no/index.html一切/永遠不會改變
這似乎工作,但我有一個問題。 「something.example.com」 需要更有活力
$( 'slavearticle a.headlinelink')。點擊(函數(){
VAR URL = $(本).attr ( 'href' 屬性);
URL = url.replace(something.example.com, 'betterexample.no');
window.location.href = URL;
});
的缺點是,我有需要此功能的50名不同的網站。有什麼辦法可以在/之後獲得所有內容,以便這可以在任何網站上使用?
退房工作pushState的https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history –
你從來沒有用新值設置href!你似乎在第一部分中有一個額外的/。 – epascarello
,你想要點擊鏈接?如果是這種情況,爲什麼不在沒有替換鏈接的情況下重定向呢? – dajavax