在Wordpress中确认留在外部链接 [英] Confirm Leave on External Links in Wordpress

查看:97
本文介绍了在Wordpress中确认留在外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一种情况:


  • 这是一家银行网站,所以当用户点击一个外部链接时Facebook页面或合作伙伴网站),则需要有一个框显示您即将离开此页面,这些内容都不会由...等管理。 用户应该可以点击'确认'在新窗口中打开外部链接或点击'取消'返回网站和一个表示你选择不离开该网站的框。




这个网站在Wordpress中,所以我正在寻找一种简单的方法来处理这个问题,而不必添加自定义Javascript到每一个环节。



他们实际上在现有网站上工作: http:// clearmountainbank .com / ,我可以通过在标题中添加confirm_entry脚本并向每个链接添加自定义Javascript来使其在新网站上工作,但我无法在新窗口中打开链接。

这种方式也非常耗时,因为我必须手动编辑每个外部链接。是否有任何简单的方法可以识别外部链接,并在整个网站中添加此功能,如果没有,我可以做些什么来使它在新窗口中打开?



我使用的代码:

 < script type =text / javascript> 
<! -
函数confirm_entry(varible_value)
{
input_box = confirm(链接免责声明:银行名称提供了不属于银行名称的网页的链接网站或clearmountainbank.com或online.bankname.com域名,这些网站不在Bank Name控制之下,Clear Mountain Bank不负责您可能在其中找到的信息或链接,Bank Name仅提供这些链接作为方便。这些链接在任何银行名称网站上的存在并不意味着银行名称认可该网站,而是提供与由其他组织,公司或个人管理的相关网站的便捷链接。
if(input_box == true)

{
window.location.href = varible_value;
}

else
{
//单击取消时输出
alert(您选择不离开银行网站。);
}

}
- >
< / script>


解决方案

以下是您可以做到的一种方法(见JSFiddle)

 <$ c $(this).attr(href).indexOf(http://)== 0 $($)$(a)。 ){
return confirm(Super long message);
}
});




  • 这只适用于 http:/ / 而不是 https:// ,它也不会检查绝对链接是否指向您当前的域,但它会给您和主意如何接近它。


Here's the situation:

  • This is a bank website, so when a user clicks an external link (perhaps to a Facebook page or a partner website), there needs to be a box that says "You are about to leave this page, none of this content is managed by...etc.".

  • The user should then be able to click 'confirm' to open the external link in a new window or click 'cancel' to be taken back to the website and a box saying "you have chosen not to leave the site".

This site is in Wordpress, so I'm looking for an easy way to handle this without having to add custom Javascript to every link.

They actually have it working on their existing site: http://clearmountainbank.com/ and I can make it work on the new site by adding a confirm_entry script to the header and adding custom Javascript to each link but I can't get the links to open in a new window.

This way is also time-consuming as I have to manually edit every external link. Would there be any easy way to recognize external links and add this functionality throughout the site and if not, what can I do to make it open in a new window?

Here's the code I'm using:

    <script type="text/javascript">
        <!--
            function confirm_entry(varible_value)
            {
            input_box=confirm("Link Disclaimer:  Bank Name  provides links to web pages which are not part of the Bank Name website or clearmountainbank.com or online.bankname.com domains. These sites are not under Bank Name control, and Clear Mountain Bank is not responsible for the information or links you may find there. Bank Name is providing these links only as a convenience. The presence of these links on any Bank Name website is not intended to imply Bank Name endorsement of that site, but to provide a convenient link to relevant sites which are managed by other organizations, companies, or individuals.");
            if (input_box==true)

            { 
            window.location.href=varible_value; 
            }

            else
            {
            // Output when Cancel is clicked
            alert ("You have opted not to leave Bank's website.");
            }

            }
        -->
    </script>

解决方案

Here's one way you could do it (See JSFiddle):

$("a").on("click", function() {
    if($(this).attr("href").indexOf("http://") == 0) {
        return confirm("Super long message");
    }
});

  • This would only work for http:// and not https://, it also doesn't check whether the absolute link points to your current domain, but it gives you and idea of how to approach it.

这篇关于在Wordpress中确认留在外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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