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.

  • "ronaldtichelaar" started this thread

Posts: 27

Location: the Netherlands

Occupation: Apple Consultant & Engineer

  • Send private message

1

Wednesday, November 5th 2008, 9:07pm

random pano on pageload

Hi,

I'm working on a new design for my website and want a random pano on the top of my site, this is what i have so far...

http://www.ronaldtichelaar.nl/toppano/


After searching forums for to days and experimenting with java i give up. So my question is as follows...

I want the pano in the frame to change after a pageload by loading a random xml or jpg file. Can this be done in javascript, AS3 or another programming language? What is the best way?

Best,
Ronald Tichelaar

This post has been edited 1 times, last edit by "ronaldtichelaar" (Nov 5th 2008, 9:46pm)


2

Wednesday, November 5th 2008, 9:43pm

Hi,

great site!
but you shouldn't use the name "banner" for the directory,
my add-blocker (Adblock Plus, Firefox) blocked it

changing the pano randomly every refresh can be done very easily with javascript (one line of code),

for example - let's assume you have 4 panos, named:
top1.xml
top2.xml
top3.xml
top4.xml

to choose one of them randomly: (code for your site)

Source code

1
2
3
4
5
6
7
8
9
10
<script type="text/javascript">

    var random_xml =  "top" + (1+Math.ceil(Math.random()*3)) + ".xml";

    swfobject.embedSWF("./krpano.swf", "krpano1", "1024", "249", "9.0.28", 
                       "swfobject21/expressInstall.swf",
                       {pano:random_xml}, 
                       {allowfullscreen:false, bgcolor:"#000000"}, 
                       {id:'krpano1', name:'krpano1'});
</script>


best,
Klaus

  • "ronaldtichelaar" started this thread

Posts: 27

Location: the Netherlands

Occupation: Apple Consultant & Engineer

  • Send private message

3

Wednesday, November 5th 2008, 9:48pm

Thanks Klaus! I've changed the directory to toppano, hope this is better... :rolleyes: Also changed it in the post. I will try your hint ASAP.

This post has been edited 1 times, last edit by "ronaldtichelaar" (Nov 6th 2008, 12:35am)


  • "ronaldtichelaar" started this thread

Posts: 27

Location: the Netherlands

Occupation: Apple Consultant & Engineer

  • Send private message

4

Wednesday, November 5th 2008, 11:12pm

OK, I'm finished and it is working. I've modified your script to pick 20 xml files and modified the random formula.


for 4 xml files...

Source code

1
    var random_xml =  "top" + (1+Math.ceil(Math.random()*3)) + ".xml";

This way it seemed like it would never pick 1.xml so I changed it to...

Source code

1
 var random_xml = "top" + (Math.ceil(Math.random()*4)) + ".xml";

After some reloads this looked better. Could this modification cause other problems?


Thanks again.
Ronald

This post has been edited 2 times, last edit by "ronaldtichelaar" (Nov 6th 2008, 12:37am)


5

Thursday, November 6th 2008, 5:45pm

you're right,

sorry, I mixed up "ceil" (rounding up) and "floor" (rounding down)

so you can use:

Source code

1
var random_xml =  "top" + (1+Math.floor(Math.random()*3)) + ".xml";

or:

Source code

1
var random_xml =  "top" + (Math.ceil(Math.random()*4)) + ".xml";


BTW - absolutely great panos!

regards,
Klaus

Yomas

Intermediate

Posts: 190

Location: Anglet, France

  • Send private message

6

Tuesday, October 25th 2011, 12:12pm

Random pano with if iphone / if android / if flash

Hi guys !
I'm upping this thread cause I try to do something similar, but with the creatpanoviewer isdevice method.
For now on I did a php script using the php rand but I have troubles in the iPhone, it's loading both iPhone and Android tour within the same page.
Maybe there'll be another way doing this ?
Here's my code :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

// Creates 3 tables for each tour version

$iphone = array ('iphone.xml', 'iphone1.xml', 'iphone2.xml', 'iphone3.xml');
$random1 = $iphone[rand(0, 3)];

$android = array ('android.xml', 'android1.xml', 'android2.xml', 'android3.xml');
$random2 = $android[rand(0, 3)];

$flash = array ('flash_tour.xml','flash_tour1.xml','flash_tour2.xml','flash_tour3.xml');
$random3 = $flash[rand(0, 3)];

?>
<!DOCTYPE html>
<html lang="fr">
<head>
<script src="js/tour.js"></script>
</head>
<body>

	<div style="width:100%; height:400px; z-index:100; background-color:none;" data-role="none" id="pano"> 
		<noscript> 
				<b>Attention:</b> <br/> 
				<br/> 
				Javascript is not activated. <br/> 
				<br/> 
				Please activate it to see the virtual tour <br/> 
		</noscript> 
				<script type="text/javascript">
						var viewer = createPanoViewer({swf:"tour.swf", id:"krpanoSWFObject", target:"pano"});
						//viewer.useHTML5("always");
						if( viewer.isDevice("iPhone|iPod|iPad") )
						{
							viewer.addVariable("xml", "<?php echo $random1; ?>"); <!-- Returns a random xml from the variable $iphone -->
							viewer.addVariable("showErrors", "false");  
							viewer.embed();
						}
						if( viewer.isDevice("Android") )
						{
							viewer.addVariable("xml", "<?php echo $random2; ?>"); <!-- Returns a random xml from the variable $android -->
							viewer.addVariable("showErrors", "false");  
							viewer.embed();
						}
						else
						{
							viewer.addVariable("xml", "<?php echo $random3; ?>"); <!-- Returns a random xml from the variable $flash -->
							viewer.addVariable("showErrors", "false");  
							viewer.embed();
						}
                </script>

	</div> <!-- end of krpanoDIV -->
 
</body> 
</html>


Thanks in advance and hoping this could help some of you ^^
My website: www.eboovisite.com, See me also on www.Viewat.com, Facebook and Twitter

Yomas

Intermediate

Posts: 190

Location: Anglet, France

  • Send private message

7

Tuesday, October 25th 2011, 3:23pm

[SOLVED]

Hi again ^^
I've changed the PHP script and by the way I messed up in the loading script, the following resolves it :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
// Création des tableaux pour le random
$iphone = array ('iphone.xml', 'iphone1.xml', 'iphone2.xml', 'iphone3.xml');
$android = array ('android.xml', 'android1.xml', 'android2.xml', 'android3.xml');
$flash = array ('flash_tour.xml','flash_tour1.xml','flash_tour2.xml','flash_tour3.xml');
?>
<!DOCTYPE html>
<html lang="fr">
<head>
</head>
<body>

	<div style="width:100%; height:400px; z-index:100; background-color:none;" data-role="none" id="pano"> 
		<noscript> 
				<b>Attention:</b> <br/> 
				<br/> 
				Javascript is not activated. <br/> 
				<br/> 
				Please activate it to see the virtual tour <br/> 
		</noscript> 
    <script src="js/tour.js"></script>
				<script type="text/javascript">
						var viewer = createPanoViewer({swf:"tour.swf", id:"krpanoSWFObject", target:"pano"});
						//viewer.useHTML5("always");
						if( viewer.isDevice("iPhone|iPod|iPad") )
						{
							viewer.addVariable("xml", "<?php echo $iphone[array_rand($iphone)]; ?>");
							viewer.addVariable("showErrors", "false");  
							viewer.embed();
						}
						else if( viewer.isDevice("Android") ) <!-- Here I'd forgot the else if I was using else -->
						{
							viewer.addVariable("xml", "<?php echo $android[array_rand($android)]; ?>");
							viewer.addVariable("showErrors", "false");  
							viewer.embed();
						}
						else
						{
							viewer.addVariable("xml", "<?php echo $flash[array_rand($flash)]; ?>");
							viewer.addVariable("showErrors", "false");  
							viewer.embed();
						}
                </script>

	</div> <!-- end of krpanoDIV -->
 
</body> 
</html>


Cheers !!
My website: www.eboovisite.com, See me also on www.Viewat.com, Facebook and Twitter

Similar threads