-1

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?

Edoardo
  • 17
  • 6

1 Answers1

0

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.
});
TastySpaceApple
  • 3,115
  • 1
  • 18
  • 27
  • This is the problem. Unfortunately, the proposed solution did not solve the problem. Webkit sends the Bind function immediately. – Edoardo Dec 18 '13 at 19:42
  • I found a similar discussion at this link -> [link](http://stackoverflow.com/a/10603433/3108307) Is the solution I'm looking for? – Edoardo Dec 18 '13 at 19:46
  • I solved precedentemenet linked with the post. Thanks for the help :) – Edoardo Dec 18 '13 at 19:49