繁体   English   中英

打开弹出窗口会返回错误

[英]Opening a pop-up window returns error

function RequestTickets(url) {
var settings = 'height=500,width=400,location=no,resizable=no,scrollbars=no,status=no,
    titlebar=yes,toolbar=no';
var newwindow = window.open(url, '-- Ticket Request Form --', settings, false);
if (window.focus) { newwindow.focus() };
return false;
}

我在umbraco页面中的以下html代码调用了上述javascript。

<a href="javascript:RequestTickets('/us/home/requestform.aspx')">here</a> to request tickets for an event.

我不断收到一个JavaScript错误,说未定义newwindow。 困惑为什么我一直清楚地定义它不断发生! 请帮忙

通常,我通过addEventListener(在大多数情况下为jQuery事件)在html元素和javascript函数之间创建绑定,而不是在html中。

document.getElementById('action-request-tickets').addEventListener('click', function(event){
    event.preventDefault();

    var settings = 'height=500,width=400,location=no,resizable=no,scrollbars=no,status=no,titlebar=yes,toolbar=no';
    var newwindow = window.open(this.href, '-- Ticket Request Form --', settings, false);
    if (window.focus) { 
        newwindow.focus() 
    };
    return false;
});

http://jsfiddle.net/DvHnP/

Benifit:您可以重复使用此函数,因为它从中获取href(带有id action-request-tickets的元素)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM