Function is called on the first page load with webkit

97 views Asked by At

I have a function to click a link that takes the url as an attribute of the link and then sends an ajax request to the url and prints the result in a div on the main page. You can read the source at this link -> history.ajax.js

The function is called at the click of a link, the link is essentially formed in this way:

<a onclick="ajaxLoadContent(this)" link="url_a">Link</a>

Unfortunately with webkit function is activated when the page first loads, thus forming errors. Why webkit launches instantly without function if it was not clicked any links?

1

There are 1 answers

3
TastySpaceApple On

I don't know of any issue about webkit spontaneously launching events defined as "onlclick"...

From a quick look at your code I think the problem might be in the second function $(window).bind('pops.....

It's unsafe to use jquery in the script without first determining that jquery was load. like so:

function bind(){
    $(window).bind('popstate', function () {
        $.ajax({
            url: location.pathname,
            success: function (data) {
                $('div#front').html(data);
            }
        });
    });
}

$(function(){ //make sure jquery was loaded...
    bind(); //any code that goes here is jquery-safe.
});