异步Iframe不工作

异步Iframe不工作,iframe,asynchronous,Iframe,Asynchronous,我有以下代码在加载主页之后加载iframe内容 <head> <title></title> </head> <body> <script> (function(d){ var iframe = d.body.appendChild(d.createElement('iframe')), doc = iframe.contentWindow.document; // styl

我有以下代码在加载主页之后加载iframe内容

<head>
    <title></title>
</head>
<body>
    <script>
    (function(d){
    var iframe = d.body.appendChild(d.createElement('iframe')),
    doc = iframe.contentWindow.document;

    // style the iframe with some CSS
    iframe.style.cssText = "position:absolute;width:200px;height:100px;left:0px;";

    doc.open().write('<body onload="' + 
   'var d = document;d.getElementsByTagName(\'body\')[0].' + 
   'appendChild(d.createElement(\'script\')).src' + 
   '=\'http:\/\/google.com\'">');

   doc.close();

   })(document);
 </script>
</body>

(职能(d){
var iframe=d.body.appendChild(d.createElement('iframe')),
doc=iframe.contentWindow.document;
//使用一些CSS设置iframe的样式
iframe.style.cssText=“位置:绝对;宽度:200px;高度:100px;左侧:0px;”;
doc.open().write(“”);
doc.close();
})(文件);
不幸的是,此代码没有按预期工作。有人能指出这里出了什么问题吗


谢谢

这可能是因为从未调用过此函数。
给你的函数命名并从某个地方调用它,例如body onLoad event

当我将google.com改为
mydomain.com
时,
mydomain.com
也没有加载,但奇怪的是,我仍然在我的数据库中从我的IP得到了一个点击cPanel@aye你从哪里开始你的页面?原因可能是跨域访问。如果您的页面位于本地主机上,请尝试将iframe设置为本地页面。我尝试将其更改为同一域,但仍然无法工作。在所有情况下,我都看到iframe被加载,但是iframe中的内容没有被加载displayed@aye你在哪里运行你的函数?这是主页。在主页的iframe中