i have a html page with 2 embed pages
<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. both pages have scripts. Is there any way to pass a variable defined in a script from the toolbar to the 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 intoiframe
elements, don't forget the close tags.The W3 - Technical Review - HTML 5 - The
embed
element mentionsThe embed element represents an integration point for an external (typically non-HTML) application or interactive content.
so you should rather use
iframe
elements instead ofembed
elements, which mentions:The iframe element represents a nested browsing context.
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;
You can access the variable from within an iframe using
window.parent.myvariable
.The DOM object
window.parent
is defined as such: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.A shortened version is to use
parent.myvariable
, aswindow
is the root DOM object.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.
Domains, protocols and ports must match.
精彩评论