Loading ...
Sorry, an error occurred while loading the content.

Accessing SVG ECMAscript?

Expand Messages
  • Darryl Watson
    Hi all- It is possible to access a containing webpage s javascript functions from your SVG document thus: top.whatever_function(); Is it possible to go the
    Message 1 of 3 , Mar 27, 2006
    • 0 Attachment
      Hi all-

      It is possible to access a containing webpage's javascript functions
      from your SVG document thus:

      top.whatever_function();

      Is it possible to go the other way: to access SVG javascript (or
      ECMAscript) from its parent page? If so, what are the implications of
      having inline SVG script declared as javascript or ECMAscript?

      I'm using IE 6 and ASV 3.03, thanks!
    • Martin Honnen
      ... If you embed an SVG document in a HTML document with IE and Adobe SVG viewer then there is a method getWindow exposed on the embed element object that you
      Message 2 of 3 , Mar 27, 2006
      • 0 Attachment
        --- In svg-developers@yahoogroups.com, Darryl Watson <dwatson@...> wrote:

        > It is possible to access a containing webpage's javascript functions
        > from your SVG document thus:
        >
        > top.whatever_function();
        >
        > Is it possible to go the other way: to access SVG javascript (or
        > ECMAscript) from its parent page? If so, what are the implications of
        > having inline SVG script declared as javascript or ECMAscript?
        >
        > I'm using IE 6 and ASV 3.03, thanks!

        If you embed an SVG document in a HTML document with IE and Adobe SVG
        viewer then there is a method getWindow exposed on the embed element
        object that you can call to access the window object of the viewer
        which is also the global object meaning global functions are
        properties of that window object.

        Example HTML:

        <embed name="svg1"
        type="image/svg+xml"
        src="file.svg"
        width="200" height="200"></embed>

        Then script in the HTML document can do e.g.

        var svgDocument = null, svgWindow = null;

        window.onload = function (evt) {
        var embed = document.embeds.svg1;
        if (embed != null && typeof embed.getSVGDocument != 'undefined') {
        svgDocument = embed.getSVGDocument();
        }
        if (embed != null && typeof embed.getWindow != 'undefined') {
        svgWindow = embed.getWindow();
        }
        }

        Once that has been done you can call global functions in the SVG
        document as e.g.

        if (svgWindow != null && typeof svgWindow.functionName != 'undefined') {
        svgWindow.functionName();
        }

        It should not matter whether the script element in the SVG document
        has type="text/javascript" or type="text/ecmascript" as long as the
        viewer does not use its internal script engine. By default within IE
        it uses the MS JScript engine.
      • Darryl Watson
        Wow, very informative answer! Merci
        Message 3 of 3 , Mar 27, 2006
        • 0 Attachment
          Wow, very informative answer! Merci

          Martin Honnen wrote:

          >--- In svg-developers@yahoogroups.com, Darryl Watson <dwatson@...> wrote:
          >
          >
          >
          >>It is possible to access a containing webpage's javascript functions
          >>from your SVG document thus:
          >>
          >> top.whatever_function();
          >>
          >>Is it possible to go the other way: to access SVG javascript (or
          >>ECMAscript) from its parent page? If so, what are the implications of
          >>having inline SVG script declared as javascript or ECMAscript?
          >>
          >>I'm using IE 6 and ASV 3.03, thanks!
          >>
          >>
          >
          >If you embed an SVG document in a HTML document with IE and Adobe SVG
          >viewer then there is a method getWindow exposed on the embed element
          >object that you can call to access the window object of the viewer
          >which is also the global object meaning global functions are
          >properties of that window object.
          >
          >Example HTML:
          >
          > <embed name="svg1"
          > type="image/svg+xml"
          > src="file.svg"
          > width="200" height="200"></embed>
          >
          >Then script in the HTML document can do e.g.
          >
          > var svgDocument = null, svgWindow = null;
          >
          > window.onload = function (evt) {
          > var embed = document.embeds.svg1;
          > if (embed != null && typeof embed.getSVGDocument != 'undefined') {
          > svgDocument = embed.getSVGDocument();
          > }
          > if (embed != null && typeof embed.getWindow != 'undefined') {
          > svgWindow = embed.getWindow();
          > }
          > }
          >
          >Once that has been done you can call global functions in the SVG
          >document as e.g.
          >
          > if (svgWindow != null && typeof svgWindow.functionName != 'undefined') {
          > svgWindow.functionName();
          > }
          >
          >It should not matter whether the script element in the SVG document
          >has type="text/javascript" or type="text/ecmascript" as long as the
          >viewer does not use its internal script engine. By default within IE
          >it uses the MS JScript engine.
          >
          >
          >
          >
          >
          >
          >
          >-----
          >To unsubscribe send a message to: svg-developers-unsubscribe@yahoogroups.com
          >-or-
          >visit http://groups.yahoo.com/group/svg-developers and click "edit my membership"
          >----
          >Yahoo! Groups Links
          >
          >
          >
          >
          >
          >
          >
          >
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.