jquery function inside pageload function fires multiple times

I have a small jquery function that opens a popup window.

As my site is asp.net based and uses update panels, I place the function inside of the ajax pageLoad() function, to ensure it works after each postback.

I'm developing a new page with a number of update panels. If, after I've made several asynch postbacks, I then click on the hyperlink with the popup, the function seems to fire once for each postback that has occurred.

Here's the function:

function pageLoad() {
    $("a.popup").click(function (e) {
        if (e.preventDefault) {
            e.preventDefault();
        }
        else {
            e.returnValue = false;
        }
        window.open(this.href, this.target, 'menubar=0, toolbar=0, location=0, directories=0, status=0, scrollbars=1, resizable=0, width=1010, height=640, left=50, top=50');
    }
}

I'm at a loss to how to stop this happening. Any advice?

Answers


The event handler is getting re-bound every time the page load happens. Try this:

$("a.popup").unbind('click').click(function (e) {

Need Your Help

What is the default installation directory with an MSI install of Python 2.7?

python windows installation-path

When using windows MSI installation from python.org/download (current version is 2.7.3), python by default installs in some folder but it is nowhere documented what is this default. Can someone check

Updating one observableArray while looping another observableArray

knockout.js

Given one observableArray, populated by a service call, which is used to render a Checkbox list in a view: