Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.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的函数_Javascript_Jquery_Onclick_Window - Fatal编程技术网

单击转换为javascript的函数

单击转换为javascript的函数,javascript,jquery,onclick,window,Javascript,Jquery,Onclick,Window,我写这个脚本是为了当用户点击我们网站外部的任何链接时弹出一个确认对话框。它在我们的上的性能与预期一样,但是当我尝试在我们的上运行此脚本时,它完全没有任何作用。我相信它正在阻止jQuery运行。您对将此脚本转换为javascript有何建议 <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> <script src="http://code.

我写这个脚本是为了当用户点击我们网站外部的任何链接时弹出一个确认对话框。它在我们的上的性能与预期一样,但是当我尝试在我们的上运行此脚本时,它完全没有任何作用。我相信它正在阻止jQuery运行。您对将此脚本转换为javascript有何建议

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script type="text/javascript">

    $(function(){
        $('a').click(function(){

        if ((this.href.toLowerCase().indexOf("myfloridalicense.custhelp") > -1) || 
            (this.href.toLowerCase().indexOf("myfloridalicense") > -1) ||
            (this.href.toLowerCase().indexOf("javascript") > -1) ||
            (this.href.toLowerCase().indexOf("dbprftp") > -1) ||
            (this.href.toLowerCase().indexOf("interredesignalpha") > -1) ||
            (this.href.toLowerCase().indexOf("bpr") > -1))
        {

            //Throw away
        } 
        else {
            if (window.confirm('NOTICE: By accessing this link, you will be leaving the DBPR website. DBPR is not responsible for the content of the Internet website you are entering. DBPR neither warrants nor makes any representations nor endorsements as to the accuracy, quality, content or completeness of the information, text, images, graphics, hyperlinks, and other items contained on the Internet website you are entering. DBPR is not responsible or liable for any viruses or contaminations of your hardware, software, peripherals or property, resulting from use of the Internet websites linked to or from the DBPR Internet website. Do you want to proceed?'))
            {
                // They clicked Yes
            }
            else
            {
                // They clicked no
                return false;
            }
        }
        });
    });
</script>
提前感谢您的帮助

功能测试{ 违约事件; var path=$'a'.prop'href'; 如果path.toLowerCase.indexOfmyfloridalicense.custhelp>-1 | path.toLowerCase.indexofmyfloridalinse>-1|| path.toLowerCase.indexOfjavascript>-1|| path.toLowerCase.indexOfdbprftp>-1|| path.toLowerCase.indexOfinterredesignalpha>-1|| path.toLowerCase.indexOfbpr>-1 { //扔掉 } 否则{ 注意:通过访问此链接,您将离开DBPR网站。DBPR不对您正在进入的互联网网站的内容负责。DBPR不对信息、文本、图像、图形、超链接等的准确性、质量、内容或完整性作任何保证、陈述或背书nd您正在输入的Internet网站上包含的其他项目。DBPR不对因使用链接到或来自DBPR Internet网站的Internet网站而导致的任何病毒或硬件、软件、外围设备或财产污染负责。是否继续?” { //他们点击“是” } 其他的 { //他们单击“否” 返回false; } } }
我的第一个猜测是,您的门户为所有锚定标记附加了一个侦听器,以防止离开门户页面。更有可能的是,jQuery没有被阻止,对锚定标记的单击被阻止

您可以通过绑定到锚标记上的mouseup事件或特定的mouseup事件来验证这一点。门户也有可能取消这些事件,但许多人只考虑绑定到单击


如果您对页面有任何控制权,请尝试将单击侦听器添加到锚定标记以外的其他内容,例如特定的div或列表项。这将回答jQuery是否处于活动状态。一旦你知道了这个问题的答案,你就可以决定下一步行动。

与Keerthi的答案相同,但使用了不引人注目的Javascript:

function test(){
 if ((this.href.toLowerCase().indexOf("myfloridalicense.custhelp") > -1) || 
            (this.href.toLowerCase().indexOf("myfloridalicense") > -1) ||
            (this.href.toLowerCase().indexOf("javascript") > -1) ||
            (this.href.toLowerCase().indexOf("dbprftp") > -1) ||
            (this.href.toLowerCase().indexOf("interredesignalpha") > -1) ||
            (this.href.toLowerCase().indexOf("bpr") > -1))
        {

            //Throw away
        } 
        else {
            if (window.confirm('NOTICE: By accessing this link, you will be leaving the DBPR website. DBPR is not responsible for the content of the Internet website you are entering. DBPR neither warrants nor makes any representations nor endorsements as to the accuracy, quality, content or completeness of the information, text, images, graphics, hyperlinks, and other items contained on the Internet website you are entering. DBPR is not responsible or liable for any viruses or contaminations of your hardware, software, peripherals or property, resulting from use of the Internet websites linked to or from the DBPR Internet website. Do you want to proceed?'))
            {
                // They clicked Yes
            }
            else
            {
                // They clicked no
                return false;
            }
        }
    }

document.getElementById('mySuperImportantLink').addEventListener('click', test, false);
HTML:


请参阅。

如何启动该弹出窗口?常见问题解答页面不加载jQuery。@Barmar我也这么想,但我成功地将mouseup事件绑定到锚定标记。我转到您的常见问题解答门户,打开开发人员工具,并将jQuery输入Javascript控制台。它说它没有定义。你的锚定标签是什么样子的?它有身份证吗?你能粘贴代码吗?非常感谢你的帮助@murmeister。我将mouseup事件绑定到锚点标记,并且可以在mouseup和mousedown上看到附加的测试文本。您建议如何实现mouseup事件来代替click侦听器?问题是如何在没有jQuery的情况下运行此代码。$'“.prop”href“是jQuery。此外,您不需要在onclick属性中使用javascript:in。即使测试函数不需要,onclick也会返回false。所以它永远不会跟随链接。嘿,非常感谢你的帮助@Keerthi!不过,我在理解这将如何工作时遇到了一个问题。URL是动态生成的,因此我没有向每个外部链接添加onClick事件的选项。使用此方法,我不必向每个外部链接附加唯一的ID吗?如果您有多个链接,所有链接都要在单击时运行测试,则可以将类mySuperClass应用于所有链接,然后对document.getElementsByClass'mySuperClass'返回的每个元素迭代并应用事件侦听器
<a href="javascript:void(0)" id="mySuperImportantLink"> Link </a>