Sai
Sai

Reputation: 712

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

I have the above javascript getting called by the following piece of html code in an umbraco page.

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

I keep getting a javascript error saying newwindow is undefined. Confused why it keeps occuring as I have clearly defined it! Please help

Upvotes: 0

Views: 207

Answers (1)

Tobias Oberrauch
Tobias Oberrauch

Reputation: 226

Normally I create the binding between a html element and a javascript function in javascript via addEventListener (in most cases with jQuery events) and not in 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: You can reuse this function because it gets the href from this (element with id action-request-tickets)

Upvotes: 1

Related Questions