dongqiulei1987 2013-01-09 09:22
浏览 17
已采纳

通过PHP离开网站免责声明?

Due to legal reasons, I want every external hyper link posted on my forum to first link to a You're leaving this website and are being redirected to a website that is not our property... -disclaimer page. Something like http://www.mydomain.com/?leave=FINALURLHERE would do fine, but how do I set up this system?

I can easily make a script that does it for all URLs, but I only want this to happen to external URLs. Can anybody push me towards the right direction?

  • 写回答

1条回答 默认 最新

  • douchui4815 2013-01-09 09:27
    关注

    Presumably you're using some form of BBCode on your forums. You can just edit that to add your leaving page first.

    If you're not, then you'll have to resort to some rather messy JavaScript. Something like:

    var links = document.getElementsByTagName('a'), l = links.length, i,
        domain = location.protocol+"//"+location.hostname+"/";
    for( i=0; i<l; i++) {
        if( links[i].href.substr(0,domain.length) != domain) {
            links[i].href = "/exit.php?target="+encodeURIComponent(links[i].href);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭