尝试在单击时打开窗口

Trying to open window on click

本文关键字:开窗口 单击      更新时间:2023-09-26

>我正在尝试在自己的窗口中打开一个javascript应用程序。我创建了一个按钮并附加了一个onclick事件,但是当我单击它时没有任何反应。我通过警报进行故障排除,但这也没有启动。

在控制台中,我收到错误:jquery.min.map 404(未找到),但我总是得到它,所以我通常忽略它。

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="description" content="$1">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>$2</title>
        <link rel="stylesheet" href="css/main.css">
        <script type="text/javascript" src="https://hosted.test.ca/kc/MD/SiteAssets/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="https://hosted.teste.ca/kc/MD/SiteAssets/jquery.SPServices-2013.01.min.js"></script>
        <script type="text/javascript">
        var $launch = $('#launchButton');
            $launch.click(function(){
                alert("opening ManagementDash");
                var url = 'https://hosted.test.ca/kc/MD/SiteAssets/mgmtDash.html';
                window.open(url,'ManagementDash','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=100%,height=100%');
                return  false;
            });
        </script>
    </head>
    <body>
    <button id="launchButton" >Launch MDash</button>
    </body>
</html>

在元素加载到 dom 之前触发脚本。

尝试将代码包装在文档中,或将其放在页面底部。

如果您检查 http://jsfiddle.net/tutZE/您的代码工作正常,因为它会为您添加准备好的文档。

$(document).ready(function(){
var $launch = $('#launchButton');
            $launch.click(function(){
                alert("opening ManagementDash");
                var url = 'https://hosted.test.ca/kc/MD/SiteAssets/mgmtDash.html';
                window.open(url,'ManagementDash','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=100%,height=100%');
                return  false;
            });
});

另一种选择是在jquery中使用.on或委托方法方法

http://api.jquery.com/on/

http://api.jquery.com/delegate/

确保已加载 jQuery 并将脚本包装在函数$( document ).ready中。

$( document ).ready(function() {
            var $launch = $('#launchButton');
            $launch.click(function(){
                alert("opening ManagementDash");
                var url = 'https://hosted.test.ca/kc/MD/SiteAssets/mgmtDash.html';
                window.open(url,'ManagementDash','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=100%,height=100%');
                return  false;
            });
 });