捕获href标签中的url
我有一个退出页面,通知用户他们要离开我的网站。我如何从引用页面捕获预期的 URL,并在用户在退出页面上确认他们知道他们要离开我的网站并希望继续前往目的地后将其发送到该 URL?我当前的设置适用于绝对链接,但不适用于相对路径。
这有效:
href="http://acme.com/company/brand/leaving/?url=http://www.about.info/choices/
这不起作用:
href="../COMPANY/BRAND/leaving/?url=http://www.about.info/choices/"
继续按钮触发以下功能:
function gbye(){
var url = window.location.toString();
var url_arr= url.split("?url=");
if(url_arr.length>1)
{
try
{
window.location = url_arr[1];
}
catch (e)
{
}
}
return false;
}
任何人都可以解释为什么带有相对路径的 href 不起作用(返回目录列表)以及如何使相对路径起作用?
I have an exit page that informs users that they are leaving my site. How do I capture the intended url from the referring page and send the user to it once they've acknowledged on the exit page that they're aware they're leaving my site and wish to continue to their destination? My current setup works with an absolute link but not with a relative path.
this works:
href="http://acme.com/company/brand/leaving/?url=http://www.about.info/choices/
this doesn't:
href="../COMPANY/BRAND/leaving/?url=http://www.about.info/choices/"
the continue button triggers the following function:
function gbye(){
var url = window.location.toString();
var url_arr= url.split("?url=");
if(url_arr.length>1)
{
try
{
window.location = url_arr[1];
}
catch (e)
{
}
}
return false;
}
can anyone explain why the href with the relative path doesn't work (returns a directory list) and how I can make the relative path work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数服务器运行在Linux环境下,其中文件系统是区分大小写的,即不同大小写的文件名被不同地处理。
如果第一个链接工作正常,请使用
../company/brand/leaving/?url=...
。我建议使用/
(绝对根)而不是../
,因为当您将文件移动到不同的目录时,您不必编辑文件使用/
。Most servers are running under a Linux environment, where the filesystem is case-sensitive, ie file names with different cases are treated different.
If the first link worked correctly, use
../company/brand/leaving/?url=...
. I recommend using a/
(absolute root) instead of../
, because you won't have to edit your files when you move the files to a different directory, when using/
.