Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    celestun (09-28-2011)

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •