可以使用substr
,然後手動應用decodeURIComponent
提取的網址:
function extractFacebookUrl(u) {
u = u.substr(u.indexOf('l.php?u=') + 8); // remove before ?u=
u = u.substr(0, u.indexOf('&')); // remove after &
return decodeURIComponent(u);
}
var link = "http://www.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=iAQDjUC4AQHjQeIXcOi8z9jamgyDk8vpuylpdaRT3aHu6Q&s=1";
var linkMobile = "http://m.facebook.com/l.php?u=http%3A%2F%2Fwww.domain.com%2F&h=BAQFX067m&s=1";
document.body.innerHTML = extractFacebookUrl(link) + "<br/>" + extractFacebookUrl(linkMobile);