函数在使用 webkit 加载的第一个页面时调用

Function is called on the first page load with webkit

本文关键字:第一个 调用 加载 webkit 函数      更新时间:2023-09-26

我有一个函数来单击一个链接,该链接将 url 作为链接的属性,然后向该 url 发送 ajax 请求并将结果打印在主页上的div 中。您可以在此链接阅读源代码 -> history.ajax.js

该函数在单击链接时调用,链接基本上是这样形成的:

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

不幸的是,webkit功能在页面首次加载时被激活,从而形成错误。为什么webkit在没有点击任何链接的情况下立即启动而没有功能?

我不知道关于

webkit 自发启动定义为"onlclick"的事件的任何问题......

通过快速浏览您的代码,我认为问题可能出在第二个函数$(window).bind('pops....

在脚本中使用 jquery 而不首先确定 jquery 是否已加载是不安全的。 像这样:

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.
});
相关文章: