Previous Thread
Next Thread
Print Thread
Hop To
Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
I have 4 photos, say they are called:

image1.jpg
image2.jpg
image3.jpg
image4.jpg

Is there any way to have it so that in a custom island they appear at random (on each page view)?

In other pages we have that is done with some javascript I belive.

Anyone able to tell me how this would be done (and if it is easy what code to put in the island)?

Thank you very much

Joined: Aug 2006
Posts: 1,649
Likes: 1
Pooh-Bah
Pooh-Bah
Joined: Aug 2006
Posts: 1,649
Likes: 1

The randomizing Javascript should work in the custom island, if done properly, I would think.... confused



GangsterBB.NET (Ver. 7.6.1.1)
PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54
2007 Content Rulez Contest - Hon Mention
UBB.classic 6.7.2 - RIP
Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
OK thanks, good start.

Anyone able to tell me what that would be wink

Thanks!

Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
Would something like this work? (ie. could I just put the below into the custom island?)

And would there be any compatibility problems with doing that?

=========================

<script type="text/javascript" language="javascript">

function randomads() {

var ads = new Array();
ads[0] = "image1.gif";
ads[1] = "image2.gif";
ads[2] = "image3.gif";

var adlinks = new Array();
adlinks[0] = "http://www.link1.com";
adlinks[1] = "http://www.link2.com";
adlinks[2] = "http://www.link3.com";

num=Math.floor(Math.random()*ads.length);

document.write("<a href=" +adlinks[num]+ " target=_blank>
<img src=" +ads[num]+ " border=0></a>")
}

</script>





thanks!

Joined: Feb 2007
Posts: 1,294
Likes: 2
Veteran
Veteran
Joined: Feb 2007
Posts: 1,294
Likes: 2
Looks like it should work.

Joined: Aug 2006
Posts: 1,649
Likes: 1
Pooh-Bah
Pooh-Bah
Joined: Aug 2006
Posts: 1,649
Likes: 1

You should keep document.write's on single lines, end each with a semi-colon, and escape the quotation marks. Something like this should work, but I'm a big groggy:

Code
document.write('<a href=\"' +adlinks[num]+ '\" target=\"_blank\">');
document.write('<img src=\"' +ads[num]+ '\" border=\"0\"></a>');

If it doesn't work, View Source on my site, near the top you should see the BANNER ROTATION script I'm using -- modified, it should work for you...


GangsterBB.NET (Ver. 7.6.1.1)
PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54
2007 Content Rulez Contest - Hon Mention
UBB.classic 6.7.2 - RIP
Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
Hi there

Can I just ask how come your code above is longer than the code in my post above?

thanks

Joined: Aug 2006
Posts: 1,649
Likes: 1
Pooh-Bah
Pooh-Bah
Joined: Aug 2006
Posts: 1,649
Likes: 1

Read what I said again... wink


GangsterBB.NET (Ver. 7.6.1.1)
PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54
2007 Content Rulez Contest - Hon Mention
UBB.classic 6.7.2 - RIP
Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
I did, but it is unfortunately unclear to me why it has changed as it has.

Thanks.

Joined: Aug 2006
Posts: 1,649
Likes: 1
Pooh-Bah
Pooh-Bah
Joined: Aug 2006
Posts: 1,649
Likes: 1

Beyond this part? "You should keep document.write's on single lines, end each with a semi-colon, and escape the quotation marks." Not sure what I'm missing here, sorry... confused


GangsterBB.NET (Ver. 7.6.1.1)
PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54
2007 Content Rulez Contest - Hon Mention
UBB.classic 6.7.2 - RIP
Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
Apparently yes, otherwise I would not be asking.

My post had one "document.write".
Yours has two.
I do not understand why that is.

Apologies for it not being clear, but that is why I am asking.

Thanks. smile

Joined: Aug 2006
Posts: 1,649
Likes: 1
Pooh-Bah
Pooh-Bah
Joined: Aug 2006
Posts: 1,649
Likes: 1
Originally Posted by willing
I do not understand why that is.


I already explained it. But if you don't wanna read and understand, then do it your way and hope for the best, sorry... wink

I'm just here to help those willing to accept it... whistle


GangsterBB.NET (Ver. 7.6.1.1)
PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54
2007 Content Rulez Contest - Hon Mention
UBB.classic 6.7.2 - RIP
Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
OK I will just accept it I suppose without understanding any explanation that you say you posted.

Thanks anyway.


Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
I'm sorry can I ask one more question, just to check before messing anything up!

Would that code all go in the island itself?
(ie. not in the header insert)

Thanks

Joined: Aug 2006
Posts: 1,649
Likes: 1
Pooh-Bah
Pooh-Bah
Joined: Aug 2006
Posts: 1,649
Likes: 1

Give it a shot. You'll want to place it after the
Code
$body = <<<EOF
and before the
Code
EOF;


GangsterBB.NET (Ver. 7.6.1.1)
PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54
2007 Content Rulez Contest - Hon Mention
UBB.classic 6.7.2 - RIP
Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
Sadly it didn't work. The header appeared but nothing else.

I put this in the custom island:

<script type="text/javascript" language="javascript">

function randomads() {

var ads = new Array();
ads[0] = "http://www.domain.com/e/photo-galleries.jpg";
ads[1] = "http://www.domain.com/e/photo-galleries.jpg";
ads[2] = "http://www.domain.com/e/photo-galleries.jpg";

var adlinks = new Array();
adlinks[0] = "http://www.link1.com";
adlinks[1] = "http://www.link2.com";
adlinks[2] = "http://www.link3.com";

num=Math.floor(Math.random()*ads.length);

document.write('<a href=\"' +adlinks[num]+ '\" target=\"_blank\">');
document.write('<img src=\"' +ads[num]+ '\" border=\"0\"></a>');

}

</script>


Any ideas kind sirs?
Thanks

Joined: Feb 2007
Posts: 1,294
Likes: 2
Veteran
Veteran
Joined: Feb 2007
Posts: 1,294
Likes: 2
Try this. The bold is what I think is missing in your code making it not work.


<script type="text/javascript" language="javascript">

function randomads() {

var ads = new Array();
ads[0] = "http://www.domain.com/e/photo-galleries.jpg";
ads[1] = "http://www.domain.com/e/photo-galleries.jpg";
ads[2] = "http://www.domain.com/e/photo-galleries.jpg";

var adlinks = new Array();
adlinks[0] = "http://www.link1.com";
adlinks[1] = "http://www.link2.com";
adlinks[2] = "http://www.link3.com";

var num=Math.floor(Math.random()*ads.length);

document.write('<a href=\"' +adlinks[num]+ '\" target=\"_blank\"><img src=\"' +ads[num]+ '\" border=\"0\"></a>');

}

</script>

Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
you also ned to call the function itself from your portal box.. just declaring a function doesn't cause it to execute.

somewhere you should do 'randomads();' wink

Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
Thanks.

Where would I do that Sirdude?

Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
Still beavering away at this but without much success. Pulls hair from head!!! wink

Anyone able to assist. I actually now want this in the top header (rather than in a custom island) - don't know if that changes things or not....

Thank you! smile

Joined: Jan 2008
Posts: 81
D
journeyman
journeyman
D Offline
Joined: Jan 2008
Posts: 81
This is what I'm using...

<head>
<script type="text/javascript" language="JavaScript">
<!-- Copyright 2002 Bontrager Connection, LLC
NumberOfImagesToRotate = 8;
FirstPart = '<img src="http://****/images/cotm/cotm';
LastPart = '.jpg" height="356" width="245">';

function printImage() {
var r = Math.ceil(Math.random() * NumberOfImagesToRotate);
document.write(FirstPart + r + LastPart);
}
//-->
</script>
</head>

</html>

<body>


<table width="250" border="0" cellspacing="0" cellpadding="0" class="forumline">
<td width="250">
<p align="center"><b>Car Of The Month! </b>
</p>
<p align="center"><font size="2"><i>Click the image to view our Car Of The Month
page.</i></font><center>
<p></p>
<p></p>
<p align="center">
<a

href="http://****.com/boards/ubbthreads.php?ubb=showflat&Number=61844&g

onew=1#UNREAD">
<script type="text/javascript" language="JavaScript"><!--
printImage();
//--></script></a></td>
</td>
</table>

</body>

Joined: Aug 2006
Posts: 1,649
Likes: 1
Pooh-Bah
Pooh-Bah
Joined: Aug 2006
Posts: 1,649
Likes: 1
Originally Posted by DougMM
This is what I'm using...

<head>
{etc}
</head>

</html>

<body>
{etc}
</body>

Seriously?? There should be no <head>, <body>, or <html> tags in custom islands or headers/footers -- they're already embedded into each page. And the </html> tag in the middle?? whistle

I'm surprised it even works... unless Threads is stripping those tags (they aren't rendering on your site, so maybe that's the case?)...



GangsterBB.NET (Ver. 7.6.1.1)
PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54
2007 Content Rulez Contest - Hon Mention
UBB.classic 6.7.2 - RIP
Joined: Apr 2007
Posts: 3,940
Likes: 1
SD Offline
Former Developer
Former Developer
Joined: Apr 2007
Posts: 3,940
Likes: 1
yah, that is not the way to do it wink

Joined: Feb 2007
Posts: 678
W
old hand
old hand
W Offline
Joined: Feb 2007
Posts: 678
So what would the way of doing it be? wink


Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
Bots
by Outdoorking - 04/13/2024 5:08 PM
Can you add html to language files?
by Baldeagle - 04/07/2024 2:41 PM
Do I need to rebuild my database?
by Baldeagle - 04/07/2024 2:58 AM
This is not a bug, but a suggestion
by Baldeagle - 04/05/2024 11:25 PM
Is UBB.threads still going?
by Aaron101 - 04/01/2022 8:18 AM
Who's Online Now
1 members (Mors), 833 guests, and 197 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Stones
Stones
by isaac, August 19
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20230217)