简体   繁体   English

Javascript未在网站上运行

[英]Javascript not running on site

On the following site ( http://www.homefresh.co.nz/gallery.html ) there is a piece of javascript up the top to dynamically change the height of my iFrame 在以下网站( http://www.homefresh.co.nz/gallery.html )上,顶部有一块javascript,可动态更改iFrame的高度

Javascript in header: 标头中的Javascript:

<script type="text/javascript" language="javascript">
<!--
function calcHeight()
{
    //find the height of the internal page
    var the_height=document.getElementById('the_iframe').contentWindow.document.body.scrollHeight;
    //change the height of the iframe
    var the_height = parseFloat(the_height) + 15;
    document.getElementById('the_iframe').height=the_height;
}
//-->
</script>

and in the page is the iFrame code: 在页面中是iFrame代码:

<iframe src="http://www.dpdesignz.co.nz/homefresh/" id="the_iframe" onLoad="calcHeight();" height="1" width="920px" scrolling="auto" frameBorder="0"></iframe>

except for some reason it's not updating 除了由于某种原因它没有更新

I have the exact same code here and it works ( http://www.dpdesignz.co.nz/homefresh/test.htm ) 我在这里有完全相同的代码,并且可以正常工作( http://www.dpdesignz.co.nz/homefresh/test.htm

Can anyone see anything stopping it? 谁能看到阻止它的东西?

The page with script and the iframe page have to be on the same domain. 包含脚本的页面和iframe页面必须位于同一域中。 This is required by the same Same origin policy because of security matters. 出于安全考虑,同一“ 相同来源”策略要求这样做。

So if you want to access document that's on www.dpdesignz.co.nz then you have to use host page that is on www.dpdesignz.co.nz domain. 因此,如果要访问www.dpdesignz.co.nz上的文档,则必须使用www.dpdesignz.co.nz域上的主机页。 That's why one of your scripts works and the other don't. 这就是为什么您的一个脚本起作用而另一个不起作用的原因。

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

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