简体   繁体   English

页面加载后执行flickr徽章代码

[英]Perform the flickr badge code after page loads

I'm using the flikr badge code (http://www.flickr.com/badge_code_v2.gne) like so 我正在像这样使用flikr徽章代码(http://www.flickr.com/badge_code_v2.gne)

<!-- Start of Flickr Badge -->
<div id="flickr_badge_uber_wrapper">
<script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?..."></script>
<p class="clear"><a href="http://www.flickr.com/photos/..." target="_blank" rel="external">see more...</a></p>
</div>
<!-- End of Flickr Badge -->

This works great, apart from it's near the top of the page and the flikr api will occasionally hang the rest of the site. 除页面顶部附近外,此方法效果很好,而flikr API有时会挂起该网站的其余部分。 To stop this I figure I could either move the html to the bottom of the page and use some extra css to stylise where I want it to go, or use some javascript to make it load later. 为了解决这个问题,我认为我可以将html移到页面底部,并使用一些额外的CSS来样式化我想要的位置,或者使用一些javascript使其稍后加载。 The former sounds like it involves a bit too much absolute positioning, while I'm a little confused how to go about the latter. 前者听起来似乎涉及太多的绝对定位,而我对如何进行后者有点困惑。

Normally this would be easy, for example: 通常这很容易,例如:

document.onload = function() {
   // Do something
}

But how do I do it with the flickr badge code, it's a link to dynamically produced javascript? 但是,我该如何使用flickr徽章代码(它是动态生成的javascript的链接)呢?

EDIT 编辑

The source from the link is ie the js pulled in: 链接的来源是js引入:

var b_txt = '';

// write the badge

b_txt+= // some html, b_txt+= called for each image.

b_txt += '<span style="position:absolute;left:-999em;top:-999em;visibility:hidden" class="flickr_badge_beacon"><img src="http://geo.yahoo.com/p?s=792600102&t=53dd558c54466a104f77d195043a008d&r=http%3A%2F%2Flocalhost%3A8000%2F&fl_ev=0&lang=en&intl=uk" width="0" height="0" alt="" /></span>';

document.write(b_txt);

Use a placeholder <div> where you want it to finally appear. 在您希望它最终出现的位置使用占位符<div> Then use jquery $(document).ready and set the innerHTML of your placeholder div to the span/img/script tag. 然后使用jquery $(document).ready并将占位符div的innerHTML设置为span / img / script标记。 place the script tag near then end of the body, and it will load last. 将script标签放置在主体的末端附近,它将最后加载。 When everything is finished loading, document.ready will be fired 一切加载完成后,将触发document.ready

Something like this 像这样

$(document).ready(
     function(){
          $("#placeholder").innerHTML("<script/span/img>");
});

A simple solution would be to pull the script tag out of the wrapper. 一个简单的解决方案是将脚本标签从包装器中拉出。 Position the flickr_badge_uber_wrapper wherever you'd like it, and then place the javascript src call at the end of the body. flickr_badge_uber_wrapper在您想要的任何位置,然后将javascript src调用放在正文的末尾。 I don't see a reason why the javascript couldn't be pulled from the wrapper and loaded later on page load. 我没有看到为什么无法从包装中提取javascript并稍后在页面加载时加载它的原因。 That should be the easiest way to keep your page from hanging. 那应该是防止页面挂起的最简单方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM