Sie sind nicht angemeldet.

Lieber Besucher, herzlich willkommen bei: krpano.com Forum. Falls dies Ihr erster Besuch auf dieser Seite ist, lesen Sie sich bitte die Hilfe durch. Dort wird Ihnen die Bedienung dieser Seite näher erläutert. Darüber hinaus sollten Sie sich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutzen Sie das Registrierungsformular, um sich zu registrieren oder informieren Sie sich ausführlich über den Registrierungsvorgang. Falls Sie sich bereits zu einem früheren Zeitpunkt registriert haben, können Sie sich hier anmelden.

1

Donnerstag, 16. Februar 2023, 12:41

how to declare function in Javacript file and use it in XML (Hotspot onclick event) ?

Hello,

please I have a question how to solve this problem:

1. in Javascript I have a declared function myFunction();
2. I embed Krpano via embedpano:

in XML I have set for hotspot: <hotspot onclick="jscall(myFunction(););" />

but it doesn't work. Can anyone advise how to declare a variable in Javascript (outside of XML) and launch it by clicking on the hotspot?

thank you in advance

kme

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

Beruf: Long time coder, product manager and 3D enthousiast

  • Nachricht senden

2

Donnerstag, 16. Februar 2023, 12:59

This works for me:

in html:

Quellcode

1
2
3
4
5
<script >
function updatehotspot(){
	alert("hello");
}
</script>

in xml:

Quellcode

1
<hotspot type="image" name="myimage" url="image-%$imagenbr%.jpg" scale="0.1" ath="10" atv="0" onclick="jscall(updatehotspot())" />


tip: Make sure the number of parameters is matching

3

Donnerstag, 16. Februar 2023, 13:04

Hi @kme,

but it dont work.

i write my code in Svelte, but if i declare function in svelte component and if i load krpano via component, hotspot on click dont run function from svelte. *wacko*

kme

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

Beruf: Long time coder, product manager and 3D enthousiast

  • Nachricht senden

4

Donnerstag, 16. Februar 2023, 13:07

Do you have an example online?

kme

Fortgeschrittener

Beiträge: 310

Wohnort: Belgium

Beruf: Long time coder, product manager and 3D enthousiast

  • Nachricht senden

5

Donnerstag, 16. Februar 2023, 13:10

I don't know the framework, but maybe a stupid question: can you call the function from within plain javascript?
If so, you could do

hotspot onclick => javascript => Svelte function

First test
javascript function => Svelte function

if that works, do
hotspot onclick => javascript function

if that works, then
hotspot onclick => javascript function => Svelte function

should also work

Beiträge: 1 117

Wohnort: Poland, Europe

Beruf: krpano developer : virtual tours : the cms4vr owner

  • Nachricht senden

6

Donnerstag, 16. Februar 2023, 14:16

Your own professional, online cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube :: wiki.cms4vr.com

cms4vr team *thumbsup*

Fernando

Fortgeschrittener

Beiträge: 330

Wohnort: Habana, Cuba

Beruf: Architect, Photographer.

  • Nachricht senden

7

Freitag, 17. Februar 2023, 14:49

Hi, It has always been easier for me to do the function in krpano:

Quellcode

1
2
3
4
5
6
7
8
<action name="mykrpanoaction"
type="Javascript">
<![CDATA[
var video = document.getElementById("myvideo");
if (myvideo !== null) {
document.getElementById("myvideo").pause();
}]]>
</action>