You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

jeromebg

Professional

  • "jeromebg" started this thread

Posts: 795

Location: Angers - France

Occupation: Photographer

  • Send private message

1

Thursday, December 8th 2011, 10:37am

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 :

Source code

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


in my pano html page :

Source code

1
2
3
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

Source code

1
<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:

Source code

1
<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='+encodeURIComponent(document.location)+'&t='+encodeURIComponent(document.title),'sharer','toolbar=0,status=0,width=626,height=436');return false;
}

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

Many thanx !!!

jeromebg

Professional

  • "jeromebg" started this thread

Posts: 795

Location: Angers - France

Occupation: Photographer

  • Send private message

2

Thursday, December 8th 2011, 11:13am

Ok, I got it !

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

Source code

1
2
3
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 !