views:

18

answers:

1

I previously asked how to include Javascript in my page when I split the page into a MasterPage and ContentPlaceHolder (.NET 2.0 app) The issue was I only wanted the javascript functions on THAT page so I couldn't just put them on the masterpage.

Based on the answers, I will inlcude common fucntions through MasterPage and can put the page-specific function right on the content page. However, 1 question remains: Events. I have 2 Javascript functions that I wanted to load when the page loads ala the HTML below. How do you load javascript page events on the specific content page? Or in the case below, the OnKeyPress event?

<body onkeypress="javascript:keypressed();" onload="javascript:setDivVisibility();">
A: 

I would modify my functions keypressed and setDivVisibility to do a check on the location before executing the intended code given your stated constraints.

Something like this:

function keypressed() { 
   if ( window.location.href !== 'http://www.whatever.com/something/aPage.html' ) { 
       return;
   }
   // the original code here
}

It looks like you're using a windows based server, so you might want to do a toLowerCase() on the window.location.href before the comparison as case doesn't matter to windows servers. Good luck!

Josh the Goods