SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS ReferenceError: top not defined

    Wondering if someone can help me out as I hack some JavaScript.

    I'm playing with getting SVG to make XML-RPC calls, using JavaScript (ecmascript in fact).

    Found a JavaScript XML-RPC implementation which should work with Adobe's SVG 3.0 player from here: http://www.protocol7.com/archives/000800.html

    I use it in an SVG document like this;

    Code:
    <svg onload="_onload()"
         xmlns="http://www.w3.org/2000/svg"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:a3="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
         a3:scriptImplementation="Adobe">
    <script type="text/ecmascript" a3:scriptImplementation="Adobe"
        xlink:href="xmlrpc/js2xmlrpc.js" />
    <script type="text/ecmascript" a3:scriptImplementation="Adobe"
        xlink:href="xmlrpc/xmlrpc2js.js" />
    <script type="text/ecmascript" a3:scriptImplementation="Adobe"
        xlink:href="xmlrpc/p7svgXmlRpc.js" />
    <script>
    <![CDATA[
    
    function _onload(){
    	var x = new p7.xmlrpc("http://localhost/svg/listener.php")
    	x.addFunction("echo", _callback)
    	x.echo("hello world")
    }
    
    function _callback(data){
    	alert(data)
    }
    
    ]]>
    </script>
    
    </svg>
    So far so good. The problem lies in the JavaScript library I'm including here;

    Code:
    <script type="text/ecmascript" a3:scriptImplementation="Adobe"
        xlink:href="xmlrpc/p7svgXmlRpc.js" />
    When I view the above document with Adobe's SVG Player I get the error;

    "Line 5 ReferenceError: top not defined"
    The offending line is here;

    Code:
    if(typeof(p7)!="object") p7 = new Object()
    
    p7.xmlrpc = function(url){
    	this.url = url
    	this.proxy = null
    	if(typeof(top.p7xmlrpcCallbacks)=="undefined") top.p7xmlrpcCallbacks = []
    	this.rndID = "p7xmlrpc" + Math.round(Math.random()*10000)
    
    ...etc...
    For some reason it doesn't like the use of a reference to the "top" object. Why is beyond my JavaScript hacking abilities.

    Anyone see what the problem is or can suggest a workaround? Would be a big help.

    Thanks.

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, have you tried replacing 'top' with 'window' or 'self' ?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •