Hi,
My apologies for my 1st post being a request for help… ?
Right, the scenario….
I have a bunch of HTML files which are adds to be included on sites all over the place. One file at a time, at random, would be included, and displayed on other sites and pages.
They are sometimes just a banner image with a link, other times, they are quite a bit of HTML, with a form, and more.
They all sit on 1 domain. Now, if being called from this same domain, it’s very easy.
On the SAME domain, I can do this in PHP:
[CODE]
srand((float) microtime() * 10000000);
$add[1]=’1.html’;
$add[2]=’2.html’;
$add[3]=’3.html’;
$add[4]=’4.html’;
$add[5]=’5.html’;
$rn = array_rand($add);
include(“$add[$rn]”);
BUT, I can’t call that PHP file from different domains.
JS can be executed from different domains.
My JS is non-existent. ?
Any ideas on what the JS file should look like?
I know once I have the JS, I can just call it in HTML using <script></script>
Appreciate any help you can offer.
Kind Regards,
Richelo Killian
[code=html]<script type="text/javascript">
var myads =
[
'1.html',
'2.html',
'3.html',
...etc...
'n.html'
];
document.writeln('<iframe src="', myads[Math.round(Math.random()*(myads.length-1))],
'" style="border:0 solid black;"></iframe>');
</script>[/code]
That would work, BUT, I would prefer to include a single JS file on MANY pages, and when I need to update the adds, I can just update the 1 JS file, instead of all the pages the code lives on.[/QUOTE]
[CODE]
<script type="text/javascript">
var myads =
[
'1.html',
'2.html',
'3.html',
'4.html',
'5.html'
];
document.writeln('<iframe src="', myads[Math.round(Math.random()*(myads.length-1))],'" style="border:0 solid black;"></iframe>');
</script>
[/CODE]
[CODE]
<script language=javascript src="http://www.imnica.com/adds/test.js"></script>
[/CODE]
Nope, did not work.
I put the following in test.js on 1 server:
[CODE]
[/quote]
<script type="text/javascript">
</script>
[/CODE]
[CODE]Math.round(Math.random()*(myads.length-1))[/CODE]
[CODE]Math.floor(Math.random()*myads.length)[/CODE]
[CODE]
var myads =
[
'1.html',
'2.html',
'3.html',
'4.html',
'5.html'
];
document.writeln('<iframe src="', Math.floor(Math.random()*myads.length)],'" style="border:0 solid black;"></iframe>');
[/CODE]
[CODE]
var myads =
[
'/adds/1.html',
'/adds/2.html',
'/adds/3.html',
'/adds/4.html',
'/adds/5.html'
];
document.writeln('<iframe src="', myads[Math.floor(Math.random()*myads.length)],'" style="border:0 solid black;"></iframe>');
[/CODE]
[CODE]
var myads =
[
'http://www.imnica.com/adds/1.html',
'http://www.imnica.com/adds/2.html',
'http://www.imnica.com/adds/3.html',
'http://www.imnica.com/adds/4.html',
'http://www.imnica.com/adds/5.html'
];
document.writeln('<iframe src="', myads[Math.floor(Math.random()*myads.length)],'" style="border:0 solid black;"></iframe>');
[/CODE]
[CODE]<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
?>[/CODE]
Wow, NO IDEA why you see that! I run WP on the main domain, in the root dir, and I loaded the test file in the root dir, but, you should NOT see that!
How do you get to that?![/QUOTE]
ONLY things is now that it still only displays 1 of the 5 files, even after clearing cache, and refreshing.[/QUOTE]
[CODE]document.writeln('<iframe src="', myads[Math.floor(Math.random()*myads.length)],'" width="100%" frameborder=0 height="100%"></iframe>');[/CODE]
[CODE]var _x = Math.floor(Math.random()*myads.length);
document.writeln('<iframe src="', myads[_x], '?', _x, '" width="100%" frameborder=0 height="100%"></iframe>');[/CODE]
[code=html]<iframe src="http://www.imnica.com/adds/5.html?4" id="addframe" name="addframe" width="100%" frameborder="0" height="100%"></iframe>
<iframe src="http://www.imnica.com/adds/2.html?1" id="addframe" name="addframe" width="100%" frameborder="0" height="100%"></iframe>
<iframe src="http://www.imnica.com/adds/1.html?0" id="addframe" name="addframe" width="100%" frameborder="0" height="100%"></iframe>
<iframe src="http://www.imnica.com/adds/5.html?4" id="addframe" name="addframe" width="100%" frameborder="0" height="100%"></iframe>
<iframe src="http://www.imnica.com/adds/4.html?3" id="addframe" name="addframe" width="100%" frameborder="0" height="100%"></iframe>[/code]
0.1.9 — BETA 5.20