2011-02-19 70 views
0

我想在我的网站上实现Google日历到iframe,我知道Google有它自己的代码,但日历不是可编辑的。嵌入JavaScript到iframe

我已经尝试了一些东西,但我没有这方面的知识。任何人都可以帮助我吗?

<style> 
input.createtable { 
display:none; 
} 
</style> 
    <script language="JavaScript"> 
<!-- 
writeConsole = function(content) { 
top.consoleRef=window.open('','myconsole2', 
    'width=800,height=800' 
    +',menubar=0' 
    +',toolbar=0' 
    +',status=0' 
    +',scrollbars=1' 
    +',resizable=1') 
// top.consoleRef.document.open("text/html","replace"); 
top.consoleRef.document.writeln(
'<iframe <script src="http://www.gmodules.com/ig/ifr? 
url=http://addthisshare.com/calendar3.xml&amp;up_calendarSources=& 
amp;up_calendarColors=&amp;up_calWkst=2&amp;up_calDefaultView=MONTH 
&amp;up_calHeight=375&amp;up_calShowPrint=0&amp;up_calShowCals=1 
&amp;up_calShowTabs=1& amp;up_calShowDate=1&amp;up_calShowNav=1 
&amp;up_calNoActive=&amp;up_calTimeZone=Europe%2FAmsterdam 
&amp;synd=open&amp;w=805&amp;h=390&amp;title=Google+Calendar 
&amp;border=http%3A%2F%2Fwww.gmodules.com%2Fig%2Fimages%2F 
&amp;output=js"></script>"></iframe>' 
) 
top.consoleRef.document.close() 
} 
//--> 

+0

你能更具体地了解错误吗? – 2011-02-19 00:06:18

回答

0

一个IFRAME有一个src属性是你想要的iframe内显示的URL页面。

除非浏览器不支持iframe,否则将不会显示您在和</iframe>之间输入的代码。

所以,你不能期望上述两种技术同时工作。您的src-url将被使用,或者iframe标签之间的代码将被使用;从来都没有。这意味着没有办法“将javascript嵌入到iframe中”。获取脚本的唯一方法是将其添加到要加载到iframe中的源页面。

最后一点,我不认为你真的知道你在这里要求什么。你的问题的标题可能不是你想要做的,但我们需要更多的信息来解决你的实际问题。

编辑

我想我有你现在问什么更好的把握。你应该做的是忘记iframe一会儿,然后专注于让事件发挥作用。当你有这个工作时,把它放到它自己的文件中,并通过iframe的src-attribute引用该文件。通过在iframe标签本身中添加代码,任何内容都不应该“放入iframe”中。

+0

我正在寻找一种方法来添加谷歌日历到我的网站,这是可能的,但它是只读的,我需要添加事件。 – Chris 2011-02-19 01:29:33

0

Same Origin Policy可防止第三方编写可将数据插入任意网站的脚本。

如果Google没有为此提供API,则无法完成此操作。