Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 确认离开Wordpress中的外部链接_Javascript_Php_Jquery_Html_Wordpress - Fatal编程技术网

Javascript 确认离开Wordpress中的外部链接

Javascript 确认离开Wordpress中的外部链接,javascript,php,jquery,html,wordpress,Javascript,Php,Jquery,Html,Wordpress,情况如下: 这是一个银行网站,因此,当用户单击一个外部链接(可能指向Facebook页面或合作伙伴网站)时,需要有一个框,表明您即将离开此页面,这些内容都不是由…管理的 然后,用户应能够单击“确认”在新窗口中打开外部链接,或单击“取消”返回网站,并显示一个框,表明您已选择不离开网站 这个网站在Wordpress中,所以我正在寻找一种简单的方法来处理这个问题,而不必向每个链接添加自定义Javascript 他们实际上已经在他们现有的网站上运行了:我可以通过在标题中添加一个确认输入脚本并在每个链接中

情况如下:

这是一个银行网站,因此,当用户单击一个外部链接(可能指向Facebook页面或合作伙伴网站)时,需要有一个框,表明您即将离开此页面,这些内容都不是由…管理的

然后,用户应能够单击“确认”在新窗口中打开外部链接,或单击“取消”返回网站,并显示一个框,表明您已选择不离开网站

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

他们实际上已经在他们现有的网站上运行了:我可以通过在标题中添加一个确认输入脚本并在每个链接中添加自定义Javascript使其在新网站上运行,但我无法在新窗口中打开链接

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

以下是我使用的代码:

    <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>

这里有一种方法可以做到:

这只适用于http://而不适用于https://,它也不会检查绝对链接是否指向您当前的域,但它会告诉您如何接近它。
这里有一种方法可以做到:

这只适用于http://而不适用于https://,它也不会检查绝对链接是否指向您当前的域,但它会告诉您如何接近它。 我无法确认是否可以工作。但是,感谢以下问答,我做了一个选择:

您可以在theme的functions.php中应用这些代码,但最好是

我无法确认是否可以工作。但是,感谢以下问答,我做了一个选择:

您可以在theme的functions.php中应用这些代码,但最好是


非常感谢您的回复。不幸的是,Javascript并不是我的强项。我已经试着把它添加到我的标题中,但是我在链接点击上没有收到任何消息。我肯定我做错了什么:没问题,好吧,1你有脚本类型的文本。。不是啊,好的。修正了我的错误,但仍然没有看到任何事情发生。抱歉给你添麻烦了。真的很感谢你的帮助。不,你这样做确实有效,但它给了你一个警告,任何一个以http://www.asayopreview.com/cmb,如果您想查找没有该地址的内容,则可以将其索引为…==-1.谢谢你。再次感谢,非常感谢你的回复。不幸的是,Javascript并不是我的强项。我已经试着把它添加到我的标题中,但是我在链接点击上没有收到任何消息。我肯定我做错了什么:没问题,好吧,1你有脚本类型的文本。。不是啊,好的。修正了我的错误,但仍然没有看到任何事情发生。抱歉给你添麻烦了。真的很感谢你的帮助。不,你这样做确实有效,但它给了你一个警告,任何一个以http://www.asayopreview.com/cmb,如果您想查找没有该地址的内容,则可以将其索引为…==-1.谢谢你。再次感谢你。
$("a").on("click", function() {
    if($(this).attr("href").indexOf("http://") == 0) {
        return confirm("Super long message");
    }
});
add_action( 'wp_enqueue_scripts', 'enqueue_scripts_so_22382151' );
add_action( 'wp_header', 'print_header_so_22382151' );
add_action( 'wp_footer', 'print_footer_so_22382151' );

/**
 * Enqueue jQuery Dialog and its dependencies
 * Enqueue jQuery UI theme from Google CDN
 */
function enqueue_scripts_so_22382151() {
    wp_enqueue_script( 'jquery-ui-dialog', false, array('jquery-ui','jquery') );
    wp_enqueue_style( 'jquery-ui-cdn', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/dot-luv/jquery-ui.min.css' );
}    


/**
 * Print Dialog custom style
 */
function print_header_so_22382151() { 
    ?>
    <style>
        /* A class used by the jQuery UI CSS framework for their dialogs. */
        .ui-front {
            z-index:1000000 !important; /* The default is 100. !important overrides the default. */
        }
        .ui-widget-overlay {
            opacity: .8;
        }
    </style>
    <?php
}

/**
 * Print Dialog script
 */
function print_footer_so_22382151() { 
    $current_domain = $_SERVER['SERVER_NAME'];
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
          $('a[href^="http://"],a[href^="https://"]')
            .not('[href*="<?php echo $current_domain; ?>"]')
            .click(function(e) {
                e.preventDefault();
                var url = this.href;
                $('<div></div>').appendTo('body')
                    .html('<div><h6>Link Disclaimer:  [...].</h6></div>')
                    .dialog({
                        modal: true, title: 'message', zIndex: 10000, autoOpen: true,
                        width: 'auto', resizable: false,
                        buttons: {
                            Yes: function () {
                                window.open(url);
                                $(this).dialog("close");
                            },
                            No: function () {
                                $(this).dialog("close");
                            }
                        },
                        close: function (event, ui) {
                            $(this).remove();
                        }
                    });
            })
        });
    </script>
    <?php 
}