Call parent function

  • Hi, I'm trying to include social share buttons in my panoramas wich javascript, so this is how I do it :

    in my xml file :

    Code
    <plugin name="facebook"  onclick="js( add_to_facebook() );" />

    in my pano html page :

    Code
    function add_to_facebook() {
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(document.location)+'&t='+encodeURIComponent(document.title),'sharer','toolbar=0,status=0,width=626,height=436');return false;
    }

    this works perfect, but the problem is that I open my panoramas in a shadowbox, if I call my panorama this way in the shadowbox

    Code
    <a class="modal" href="krpano.swf?xml=http://www.mydomain.com/mypano.xml">Launch Pano</a>


    it calls the function from the parent page wich is what I want (to have the url of the parent page)

    but I would like to call my panorama this way:

    Code
    <a class="modal" href="http://www.mydomain.com/mypano.html">Launch Pano</a>


    for many reasons (analytics tracking, mobile compatibility...)

    the problem is that if I call my pano with it's html page, then the onclick="js( add_to_facebook() ) calls the function from mypano.html and not from the parent page... (am I clear ?)

    Is there a way to create a javascript function in mypano.html page wich would call my add_to_facebook() function from the parent page :
    xml : onclick="js( call_facebook() ) >>
    mypano.html: function call_facebook() {window.opener.add_to_facebook()} >>
    parent page: function add_to_facebook() {
    window.open('http://www.facebook.com/sharer.php?u='…=626,height=436');return false;
    }

    I tried with window.opener but it doesn't work... any idea ?

    Many thanx !!!

  • Ok, I got it !

    jsut have to use the window.parent in the function :

    Code
    function add_to_facebook() {
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(window.parent.document.location)+'&t='+encodeURIComponent(window.parent.document.title),'sharer','toolbar=0,status=0,width=626,height=436');return false;
    }

    it works !

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!