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.

1

Wednesday, February 7th 2018, 5:48pm

How to call a javascript function and pass the krpano interface?

Hi all,

I am trying to call a javascript function from anywhere in xml code without defining an Action and I want that function to have access to the krpano interface.

Here is an example:

Javascript code:

Source code

1
2
3
4
function myjsfunction(krpano)
 {
  krpano.trace(1, "this is a test");
 }


Xml code:

Source code

1
2
3
4
5
6
<layer name="mylayer" onloaded="myfunctionaction()" type="container" keep="true" width="100" height="100" align="center" bgalpha="1" />
<action name="myfunctionaction" type="Javascript">
  <![CDATA[
  myjsfunction(krpano);
  ]]>
  </action>


I wish to get rid of the Action and do something like that:

Source code

1
<layer name="mylayer" onloaded="js(myjsfunction(???))" type="container" keep="true" width="100" height="100" align="center" bgalpha="1" />


How can I pass the krpano interface to the javascript function when using js() to call it?

Best regards,

Antoine

2

Wednesday, February 7th 2018, 9:52pm

Hi,

just use the 'jscall' action instead of 'js' action:
https://krpano.com/docu/actions/#jscall

Then you will get automatically a krpano object inside the scope of your js function.

Best regards,
Klaus

3

Thursday, February 8th 2018, 5:48pm

Hi Klaus,

Many thanks for your quick reply.

Antoine