Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-28-2011, 02:14 AM   PM User | #1
celestun
New to the CF scene

 
Join Date: Sep 2011
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
celestun is an unknown quantity at this point
Smile Randomize the URL in an embedded link

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
celestun is offline   Reply With Quote
Old 09-28-2011, 02:37 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Code:
<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>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
celestun (09-28-2011)
Old 09-28-2011, 03:48 AM   PM User | #3
celestun
New to the CF scene

 
Join Date: Sep 2011
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
celestun is an unknown quantity at this point
Smile

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
celestun is offline   Reply With Quote
Old 09-28-2011, 04:46 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 09-28-2011, 05:40 AM   PM User | #5
celestun
New to the CF scene

 
Join Date: Sep 2011
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
celestun is an unknown quantity at this point
Smile

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
celestun is offline   Reply With Quote
Old 09-28-2011, 07:46 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Huh?

No, my code is not there, at all.

Here is what VIEW==>>SOURCE shows:
Code:
<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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 09-28-2011, 07:47 AM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Note that you are getting *TONS* Of errors out of the script.

Firebug reported at least 30 errors.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:47 PM.


Advertisement
Log in to turn off these ads.