如何使用JavaScript获取链接的重定向链接?

时间:2019-06-02 07:13:00

标签: javascript php html

我想在我的html中打开google Scholar链接。由于Google学术搜索链接正在重定向到特定网站(例如abc.com)。 abc.com在iframe中未打开。 iframe会显示该链接错误:“拒绝连接”。

<iframe src="
http://scholar.google.se/scholar_url?url=https://www.cabdirect.org/cabdirect/abstract/20193167581&hl=en&sa=X&d=11331141127468683170&scisig=AAGBfm0gdJ83JW1o6Xb82uD9bNnZNNTSeQ&nossl=1&oi=scholaralrt&hist=92LQev8AAAAJ:14285763116787501533:AAGBfm0HS_SbXaAMNGPcdwbkLaUuKU410g"></iframe>

如何使用Google学术搜索链接获取实际的链接abc.com:

示例Google链接为: http://scholar.google.se/scholar_url?url=https://www.cabdirect.org/cabdirect/abstract/20193167581&hl=en&sa=X&d=11331141127468683170&scisig=AAGBfm0gdJ83JW1o6Xb82uD9bNnZNNTSeQ&nossl=1&oi=scholaralrt&hist=92LQev8AAAAJ:14285763116787501533:AAGBfm0HS_SbXaAMNGPcdwbkLaUuKU410g

它正在重定向到该站点: https://www.cabdirect.org/cabdirect/abstract/20193167581

1 个答案:

答案 0 :(得分:0)

重定向URL存储在GET参数中。

function getRedirectLink(link) {
  var url = new URL(link);
  var redirect = url.searchParams.get("url");
  return redirect
}