Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
3/24/2010 10:47:44 PM EDT
I have a page with a bunch of dynamic links, they show up as "View" in certain table columns.  When clicked on, I want to open a popup window at the mouse position of the click.

I have it working in IE.  The View link there looks like:
<a href="#" onclick="my_popup_code('2');">View</a>

<a href="#" onclick="my_popup_code('3');">View</a>
...
function my_popup_code(part_number)
{
  var popupX = event.screenX - popupWidth;
  var popupY = event.screenY;
  open_popup(part_number, popupX, popupY);
}
where XXX is a part number specific to that row that the handler needs.

Firefox, however, fails, evidently because it has no analogue to "event."  Apparently, the only way to access the last raised event in firefox is simply to accept it as a parameter.  Thus my question:

How do I add or access the event parameter (usually called "e") in "my_popup_code(part_number)," when I also have to send a line specific parameter?  Might it look something like this?
<a href="#" onclick="my_popup_code(event, '4');">View</a>

<a href="#" onclick="my_popup_code(event, '5');">View</a>
...
function my_popup_code(e, part_number)
{
  var popupX = e.screenX - popupWidth;
  var popupY = e.screenY;
  open_popup(part_number, popupX, popupY);
}
3/25/2010 4:21:08 AM EDT
[#1]
That's how I do it and it works fine in IE and Firefox.

Example call to my JavaScript library for a pop-up calendar:

.aspx page (two different calls to the pop-up calendar function):

  

onclick="PopUpCalendar(event, '<%=Master.Page.Form.ClientID%>.<%=txtPreKickSAPProj.ClientID%>');"
onclick="PopUpCalendar(event, '<%=Master.Page.Form.ClientID%>.<%=txtEstStartDateSAPProj.ClientID%>');"


JavaScript library:

  

function PopUpCalendar(e, textBox)
{
   var calendar;
   var winX = 0;
   var winY = 0;
   
   if (e != '')
   {
       winX = e.screenX;
       winY = e.screenY;
       
       // Adjust location if part of the calendar will be displayed off the edge of the screen.
       if (winX > (screen.availWidth - 195))
           winX = winX - 195;
           
       if (winY > (screen.availHeight - 180))
           winY = winY - 180;
   }
   else
   {
       winX = (screen.availWidth / 2) - 98;
       winY = (screen.availHeight / 2) - 90;
   }
   
   calendar_window = window.open('Calendar.aspx?textBoxName=' + textBox,'calendar_window','width=195,height=180,left=' + winX + ',top=' + winY);

   calendar_window.focus();
}
3/25/2010 8:47:41 AM EDT
[#2]
Thanks, I'll give that a shot.  It's definitely how a lo of calendar popups work, I hadn't thought of that.
3/25/2010 3:52:54 PM EDT
[#3]
Thanks, Avenger, your code worked perfectly.