[英]passing javascript global variable between embeded pages or from main to embed
i have a html page with 2 embed pages 我有2个嵌入页面的html页面
<body>
<embed src ="toolbar.html" type="application/xhtml+xml" width="485px" height="60px">
<embed src="editor.svg" type="image/svg+xml" width="595px" height="842px">
</body>
the first is a toolbar (jquery ui) the second is an xml page with svg in it. 第一个是工具栏(jquery ui),第二个是其中包含svg的xml页面。 both pages have scripts. 两个页面都有脚本。 Is there any way to pass a variable defined in a script from the toolbar to the svg ? 有什么方法可以将脚本中定义的变量从工具栏传递到svg吗?
or if that isn't possible: 或如果不可能:
is there any way to pass a variable defined in the current document to an embedded page ? 有什么方法可以将当前文档中定义的变量传递给嵌入式页面?
tnx in advance 提前发送
Turn the embed
elements into iframe
elements, don't forget the close tags. 将embed
元素变成iframe
元素,别忘了close标签。
The W3 - Technical Review - HTML 5 - The embed
element mentions W3-技术评论-HTML 5- embed
元素提及
The embed element represents an integration point for an external (typically non-HTML) application or interactive content. embed元素表示外部(通常为非HTML)应用程序或交互式内容的集成点。
so you should rather use iframe
elements instead of embed
elements, which mentions: 因此,您应该使用iframe
元素而不是embed
元素, 其中提到:
The iframe element represents a nested browsing context. iframe元素表示嵌套的浏览上下文。
in which a browsing context is defined as: 浏览上下文定义为:
A browsing context is an environment in which Document objects are presented to the user. 浏览上下文是将文档对象呈现给用户的环境。
You can declaring a global variable in a script you use in the main page. 您可以在主页中使用的脚本中声明全局变量。
It is as simple as var myvariable;
它就像var myvariable;
一样简单var myvariable;
You can access the variable from within an iframe using window.parent.myvariable
. 您可以使用window.parent.myvariable
在iframe中访问变量。
The DOM object window.parent
is defined as such: DOM对象window.parent
的定义如下:
Returns a reference to the parent of the current window or subframe. 返回对当前窗口或子帧的父级的引用。
If a window does not have a parent, its parent property is a reference to itself. 如果窗口没有父窗口,则其父属性是对自身的引用。
When a window is loaded in an
<iframe>
,<object>
, or<frame>
, its parent is the window with the element embedding the window. 当将窗口加载到<iframe>
,<object>
或<frame>
,其父窗口是带有嵌入该窗口的元素的窗口。
A shortened version is to use parent.myvariable
, as window
is the root DOM object. 简化的版本是使用parent.myvariable
,因为window
是根DOM对象。
Make sure that the domains, protocols and ports of the different documents match. 确保不同文档的域,协议和端口匹配。
Unless you want to be presented with a nasty error like: 除非您想要出现一个讨厌的错误,例如:
Unsafe JavaScript attempt to access frame with URL X from frame with URL Y. 不安全的JavaScript尝试从URL Y的框架访问URL X的框架。
Domains, protocols and ports must match. 域,协议和端口必须匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.