$(window).load Chrome,Safari问题

发布于 2024-12-06 01:59:19 字数 205 浏览 1 评论 0原文

好的,这就是问题所在

$(window).load(function () {
        \\Do something
    });

,其他变体在 chrom 和 safri 中不起作用。 FF,IE opera 工作正常我搜索但没有找到任何工作解决方案有人知道如何在页面加载完成后检查 chrome、safari 吗?

Ok here is the problem

$(window).load(function () {
        \\Do something
    });

and other variations of this just don't work in chrom and safri. FF,IE opera work fine I search but didn't find any working solution someone know how to check in chrome,safari when the page has finished loading?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

过度放纵 2024-12-13 01:59:19

如果您想在页面加载时执行某些操作,您可以尝试以下代码之一。

$(document).ready(function(){
    //Page loaded
});

$(function(){
    //Page loaded
});

编辑:试试这个

window.onload = function(){
   //Page loaded
};

或者如果你想使用 jQuery 那么试试这个

$(window).bind('load', function(){
   //Page loaded
});

You can try one of the below code if you want to execute something on page load.

$(document).ready(function(){
    //Page loaded
});

OR

$(function(){
    //Page loaded
});

EDIT: Try this

window.onload = function(){
   //Page loaded
};

Or if you want to use jQuery then try this

$(window).bind('load', function(){
   //Page loaded
});
可爱暴击 2024-12-13 01:59:19

window.loaddocument.ready 都适合我,这里有一个 小提琴

Both window.load and document.ready work for me, here's a fiddle

无所的.畏惧 2024-12-13 01:59:19

我有一个页面可以在 FF 中正常加载,但在 Chrome 中不起作用,因为我有 2 个使用 $(window).load(function() 的脚本,第二个脚本似乎在图像出现之前执行。

第一个脚本检查丢失的图像并替换错误图像:

   $(window).load(function() {
    $("img").each(function(){
      var image = $(this);            
      if(image.context.naturalWidth == 0 ||
      image.readyState == 'uninitialized'){   
         $(image).unbind("error").attr(
             "src", "assets/img/image_missing.jpg"
         );
      }
 });
});  

第二个函数重新对齐一行上的元素,以防窗口大小调整(它是响应式页面):

$(window).load(function() {
        columnConform();
});

当我在 Chrome 中对此使用调试时,会执行第一个函数,但是当执行第二个函数时缺失的图像它们仅在第二个函数完成后出现。

当页面首次加载时,未找到“Socketry”的图像,因此 Spanners/Metric/Imp 会立即显示在同一行的下方

。 - 假设这是正确的,则对齐行,但是当显示“图像丢失”时,这会强制将扳手移动到下一行

,应在行对齐之前显示“图像丢失”,在这种情况下,行将正确对齐 。 ,正如他们在 Firefox 中执行此操作。

*我会发布屏幕截图,但我没有 10 个声誉 - ggrrrh!有时一张图片值 1,000 个单词... *

我猜我最好用文字描述该页面...

我有 13 张图像按 6 排显示,所以 2 个整行和第 3 行 1 个。
找不到第 6 个图像,因此第 7 个图像显示在顶行缺失图像符号的正下方,而不是作为第 2 行的第 1 个图像。
第二个脚本对齐行,假设第 7 个图像位于顶行,然后第一个脚本使“图像丢失”图像出现,这迫使第 7 个图像自行位于第 2 行。
第二个脚本需要在所有图像加载后执行。
希望这是有道理的。

I have a page that loads fine in FF but doesn't work in Chrome because I have 2 scripts using $(window).load(function() and the 2nd seems to execute before the images appear.

The first script checks for missing images and substitutes an error image:

   $(window).load(function() {
    $("img").each(function(){
      var image = $(this);            
      if(image.context.naturalWidth == 0 ||
      image.readyState == 'uninitialized'){   
         $(image).unbind("error").attr(
             "src", "assets/img/image_missing.jpg"
         );
      }
 });
});  

The second function realigns elements on a row, in case the window is resized (it's a responsive page):

$(window).load(function() {
        columnConform();
});

When I use debug on this in Chrome, the first function is executed, but when the 2nd is executed any images that are missing have not been displayed. They only appear after the 2nd function has completed.

When the page first loads, the image for "Socketry" is not found, so Spanners/Metric/Imp is displayed immediately underneath on the same row.

The 2nd script re-aligns the rows assuming this to be correct, however when "Image Missing" is then displayed, this forces the Spanners onto the next row.

"Image Missing" should be displayed prior to the row alignment, in which case the rows will align correctly, as they do in Firefox.

*I would have posted screen shots but I don't have 10 reputation - ggrrrhh! Sometimes a picture is worth 1,000 words... *

Guess I had better desctibe the page in words...

I have 13 images displayed 6 to a row, so 2 full rows and 1 on a 3rd row.
The 6th image cannot be found, so the 7th displays right under the missing image symbol on the top row, instead of as the 1st image on the 2nd row.
The 2nd script aligns the rows, assuming that the 7th image is on the top row, and then the 1st script makes the "Image Missing" image appear, which forces the 7th image to the 2nd row, on it's own.
The 2nd script needs to execute after all images are loaded.
Hope that makes sense.

柒夜笙歌凉 2024-12-13 01:59:19

我认为这不会回答你的问题,但在我的例子中 load() 不能单独在 Chrome 中工作,因为我试图加载到

> 位于另一个 内。 Chrome完全忽略了内部的存在。

尝试下载 jQuery 的未压缩版本并对其进行调试。

I don't think this will answer your question, but in my case load() wasn't working in Chrome alone because I was trying to load to a <form> that was inside another <form>. Chrome completely ignores the existence of the inner <form>.

Try downloading an uncompressed version of jQuery and debugging it.

旧梦荧光笔 2024-12-13 01:59:19

在本地主机上工作时,某些浏览器可能会发生这种情况(我在 Opera 和 Chrome 中经历过)。 “ready”事件似乎在 javascript 有机会添加侦听器之前触发,因此 $(window).ready 永远不会触发。

This can happen in some browsers (I've experienced it in Opera and Chrome) when working on localhost. The "ready" event seems to fire before the javascript has a chance to add the listener so it $(window).ready never fires.

胡渣熟男 2024-12-13 01:59:19

示例:当页面完全加载(包括图形)时运行函数。

  $( window ).load(function() {
         // Run code
         });

示例:每次加载图像时,将类 bigImg 添加到所有高度大于 100 的图像。

$( "img.userIcon" ).load(function() {
   if ( $( this ).height() > 100) {
     $( this ).addClass( "bigImg" );
   }
});

有关详细信息,请参阅 http://api.jquery.com/load-event/

Example: Run a function when the page is fully loaded including graphics.

  $( window ).load(function() {
         // Run code
         });

Example: Add the class bigImg to all images with height greater than 100 upon each image load.

$( "img.userIcon" ).load(function() {
   if ( $( this ).height() > 100) {
     $( this ).addClass( "bigImg" );
   }
});

For more information, see http://api.jquery.com/load-event/.

最单纯的乌龟 2024-12-13 01:59:19

试试这个方法:

$(document).ready(function(){
   //Do something
})

Try this way:

$(document).ready(function(){
   //Do something
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文