临睡前外部站点重定向到一个中间页 [英] Redirect to an intermediate page before going to external site

查看:237
本文介绍了临睡前外部站点重定向到一个中间页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的问题。我是一个CMS内工作,用户可以创建超链接(内部和外部),我不知道是否有检查,当用户点击一个链接,如果他们被导航到一个外部网站的好方法。我不想,如果他们使用前进/后退按钮,输入一些东西到地址栏,等我只是想将它们重​​定向到需要他们真正想去的地址,在他本网站内的网页做任何事情查询字符串,并显示5秒(左右)的消息告诉他们,他们离开我们的网站,我们不负责这有什么等等等等,因为最终用户将负责生成大部分环节,教他们实际指向在中间页面链接不太理想,所以我在想,如果有使用JavaScript一个简单的解决方案。

Here is my problem. I'm working within a CMS and users are able to create hyperlinks (both internal and external) I'm wondering if there is a good way to check when a user clicks a link if they are navigating to an external site. I don't want to do anything if they use the back/forward buttons, type something into the address bar, etc. I just want to redirect them to a page within our site that takes the address they REALLY want to go to in he query string and display a 5 second (or so) message telling them they are leaving our site and we aren't responsible for what is there etc etc. Since end users will be responsible for generating most of the links, teaching them to actually point links at the intermediate page is less than ideal so I was wondering if there is an easy solution using javascript.

推荐答案

您可以使用 jQuery的附加click事件对于那些外部的(以http某些特殊情况下,负)在您的网站的所有链接,那么这既可以显示一个模式对话框,或设置 window.location的您的中间页面(你可以钉在查询字符串变种外部URL)。您可以自定义选择器来获得外部链接,那么附加的行为:

You could use jQuery to attach a click event for all links on your site that are external (start with http, minus some special cases), which could then either show a modal dialog, or set window.location to your intermediate page (you can tack on a query string var for the external url). You can make a custom selector to get external links, then attach the behavior:

$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname);
};

$('a:external').click(function() { 
    //show your dialog box or set window.location
    //link in question will be $(this).attr('href')
});

这篇关于临睡前外部站点重定向到一个中间页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆