...

View Full Version : Randomize the URL in an embedded link



celestun
09-28-2011, 02:14 AM
Hi, I was hoping someone might have a solution to randomizing a URL in javascript... in this case for an embedded Simpleviewer link?

At the moment the link is http://timperceval.com/guiran/intro1/ but I would like to have the site randomly choose from four URLs.

The embedded code is as follows:
<!--START SIMPLEVIEWER EMBED.-->
<script type="text/javascript" src="http://timperceval.com/guiran/intro1/svcore/js/simpleviewer.js"></script>
<script type="text/javascript">
var flashvars = {};
flashvars.baseURL = "http://timperceval.com/guiran/intro1/";
simpleviewer.ready(function () {
simpleviewer.load("sv-container", "100%", "100%", "000000", true, flashvars);
});
</script>
<div id="sv-container"></div>
<!-- END SIMPLEVIEWER EMBED --

Any ideas would really help!

Thanks,

Tim

Old Pedant
09-28-2011, 02:37 AM
<script type="text/javascript">
var urls = ["http://timperceval.com/guiran/intro1/","url2","url3","url4"];
var flashvars = {};
flashvars.baseURL = urls[ Math.floor( urls.length * Math.random() ) ];
simpleviewer.ready(function () {
simpleviewer.load("sv-container", "100%", "100%", "000000", true, flashvars);
});
</script>

celestun
09-28-2011, 03:48 AM
Thank you for your rapid solution!

I pasted your code in and nothing happens. I think it's because simpleviewer requires the initial link to the simpleviewer.js file:

<script type="text/javascript" src="http://timperceval.com/guiran/intro1/svcore/js/simpleviewer.js"></script>

Is there any way to randomize this part and use the result for the link to the folder?

Very tricky and way beyond me!

Your help is very much appreciated!

Thanks,

Tim :)

Old Pedant
09-28-2011, 04:46 AM
Don't see how that's possible.

The script that loads the simpleviewer *has* to be there before you can invoke simpleviewer.read or simpleviewer.load.

I assume you used *real* URLs? Not the dummy ones that I did?

celestun
09-28-2011, 05:40 AM
Yes, I substituted the real links. Could you please take a look at the index file for me?

timperceval.com/guiran/index.html

The code you suggested is incorporated. I hope you can spot the errors I've made.

Again many thanks!

Tim

Old Pedant
09-28-2011, 07:46 AM
Huh?

No, my code is not there, at all.

Here is what VIEW==>>SOURCE shows:


<script type="text/javascript" src="http://timperceval.com/guiran/intro1/svcore/js/simpleviewer.js"></script>

<script type="text/javascript">
var flashvars = {};
flashvars.baseURL = "http://timperceval.com/guiran/intro1/";
simpleviewer.ready(function () {
simpleviewer.load("sv-container", "100%", "100%", "000000", true, flashvars);
});
</script>

Exactly what you posted in your first post.

Old Pedant
09-28-2011, 07:47 AM
Note that you are getting *TONS* Of errors out of the script.

Firebug reported at least 30 errors.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum