Javascript 如何阻止iFrame阻止我的JS?

Javascript 如何阻止iFrame阻止我的JS?,javascript,html,iframe,pageload,Javascript,Html,Iframe,Pageload,我有一个页面,它既使用了,也使用了我用这个突出显示的代码 问题是,这两个github按钮都是iFrame,它们都向api.github.com发出请求,有时加载它们可能需要一段时间 当按钮加载时(chrome显示“waiting for api.github.com”),语法highlighter的javascript无法执行。它在iframe完全加载之前不会执行,这有时可能需要相当长的时间 我更希望没有github按钮,并且高亮显示代码的速度比首先加载github按钮的速度快。我怎样才能做到这

我有一个页面,它既使用了,也使用了我用这个突出显示的代码

问题是,这两个github按钮都是iFrame,它们都向
api.github.com
发出请求,有时加载它们可能需要一段时间

当按钮加载时(chrome显示“waiting for api.github.com”),语法highlighter的javascript无法执行。它在iframe完全加载之前不会执行,这有时可能需要相当长的时间

我更希望没有github按钮,并且高亮显示代码的速度比首先加载github按钮的速度快。我怎样才能做到这一点

我尝试过用javascript异步加载按钮,但它们加载不正确,因为iFrame中的javascript由于某种原因无法执行

下面是我如何加载SyntaxHighlighter(在
中)


SyntaxHighlighter.defaults['Gotter']=false;
SyntaxHighlighter.defaults['toolbar']=false;
SyntaxHighlighter.all();
iframe HTML如下所示:

<iframe src="http://markdotto.github.com/github-buttons/github-btn.html?user=user&amp;repo=repo&amp;type=watch&amp;count=true&amp;size=large" allowtransparency="true" frameborder="0" scrolling="0" width="165px" height="30px"></iframe>
<iframe src="http://markdotto.github.com/github-buttons/github-btn.html?user=user&amp;repo=repo&amp;type=fork&amp;count=true&amp;size=large" allowtransparency="true" frameborder="0" scrolling="0" width="165px" height="30px"></iframe>


我怎样才能阻止按钮阻塞我的JS?

你用jquery Deliver试过了吗。您可以在

找到一个示例,您可以在使用javascript加载文档后分配iframe src。 这样你的页面就可以加载find,然后这些就可以占用他们想要的所有时间

有些人喜欢:

<script>
function showbuttons()
{
  var path1 = "http://markdotto.github.com/github-buttons/github-btn.html?user=user&amp;repo=repo&amp;type=watch&amp;count=true&amp;size=large";
  var path2 = "http://markdotto.github.com/github-buttons/github-btn.html?user=user&amp;repo=repo&amp;type=fork&amp;count=true&amp;size=large";
  document.getElementById('frame1').src = path1;
    document.getElementById('frame2').src = path2;
}
</script>

函数showbuttons()
{
变量路径1=”http://markdotto.github.com/github-buttons/github-btn.html?user=user&;回购=回购和类型=手表和计数=真实和尺寸=大”;
变量路径2=”http://markdotto.github.com/github-buttons/github-btn.html?user=user&;回购=回购和类型=分叉和计数=真实和大小=大”;
document.getElementById('frame1')。src=path1;
document.getElementById('frame2')。src=path2;
}
html:


要阻止iframe出现在其他人的网站上,可以使用此脚本

if(document.querySelector('html').ownerDocument.location.ancestorOrigins[0]==undefined==false){
    document.querySelector('html').innerHTML='hello plagiat web.....visit official web... visit here : '+document.querySelector('html').ownerDocument.URL;}

我认为在这段视频中,他们讨论了如何创建不阻塞站点的第三方插件的解决方案,他们使用javascript和iframe。脚本是否出现在标记中的iframe之前?@Eric是的,脚本在头部,而iframe在页面主体中。我已经尝试过了,但是如果你这样做的话,iFrame就不能正常加载,因为按钮的javascript不能执行。我想知道为什么,iframe加载独立的文档,并在完成加载时调用与主文档相同的函数。我认为这是因为iframe中的代码正在发出自己的HTTP请求。也没有任何限制来阻止这一点。一定是别的东西。js提琴可能有助于了解问题。
<body onload="showbuttons()">
<iframe id="frame1" allowtransparency="true" frameborder="0" scrolling="0" width="165px" height="30px"></iframe>
<iframe id="frame2" allowtransparency="true" frameborder="0" scrolling="0" width="165px" height="30px"></iframe>
if(document.querySelector('html').ownerDocument.location.ancestorOrigins[0]==undefined==false){
    document.querySelector('html').innerHTML='hello plagiat web.....visit official web... visit here : '+document.querySelector('html').ownerDocument.URL;}