php - 我可以等待 location.href 加载页面吗?

标签 php javascript jquery

是否可以使用 location.href 知道页面何时加载?我当前的代码如下所示,我想在页面加载完成后触发一些事件发生。我尝试使用 $.get 但它破坏了我当前的 jquery address 实现所以这行不通。

$('.search').click(function(){
    location.href = "/search.php"; 
    // trigger event here...
    return false;
});

适用于我当前的设置:

$.get('search.php', function() {
    alert('Page has finished loading');
});

还有其他选择吗?

最佳答案

你尝试过这个吗:

$(document).ready(function () {
  alert('Page has finished loading');
});

编辑:删除了答案的第二部分,因为有目的的重定向否定了它的有用性

关于php - 我可以等待 location.href 加载页面吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7612285/

相关文章:

java - 网站和 Android 应用程序的单一数据库

php - 如何查看 cron 作业中返回的 php 错误

javascript - 在javascript中获取类名时出错

jquery - 使用jquery将基于coffeescript类的数据结构上传到ruby on Rails 3?

javascript - AngularJS/解析 $http --data-urlencode

php - Mysql WHERE 子句或 php IF 条件?

php - 如何在脚本过程中管理多个错误

javascript - 收到错误请求的资源上不存在 'Access-Control-Allow-Origin' header

javascript - Bootstrap 模式中的动态内容和 Ajax [Laravel] 中的动态数据

php - 使用 .replaceWith() 后未提交某些表单值