0
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

Sai
  • 682
  • 2
  • 12
  • 35

1 Answers1

1

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)

Tobias Oberrauch
  • 217
  • 6
  • 15
  • Pardon me for the ignorance, I assume this piece of code has to be part of a javascript function inside a script tag? – Sai Oct 31 '13 at 14:58
  • Yes, you can put this function into a script tag or external javascript file. Are you using any framework like jQuery or so? – Tobias Oberrauch Oct 31 '13 at 15:26
  • No I am not using any external framework. And I am using an older version of IE. I see this works like a charm on the link you provided but when I use it in my page, the page opens up normally instead of opening as a pop-up. I am assuming event.preventDefault is not working as intended :( – Sai Oct 31 '13 at 15:28
  • Which version of IE? Have you check the developers tools on F12? – Tobias Oberrauch Oct 31 '13 at 15:38
  • I use IE8. But I have modified the code slightly. It had problems understanding addEventListener which I replaced with attachEvent and preventDefault which I got rid of. – Sai Oct 31 '13 at 16:08