SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Jul 2000
    Location
    Long Island, NY
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random link with pop-up window?

    A client has a feature on her home page which is basically a changing piece of information, not unlike the Sitepoint Tip of the Day, except that it varies a great deal in length from item to item and may contain quotations and links as well as multiple paragraphs - or not. She was using a DHTML scroller for this, but it was taking up valuable screen real estate that she really needs to explain what is is that she does, and it slowed down the page which is attractive but a bit graphics heavy and not really designed for speed as it is. I didn't design it. Someone much more expensive did that.

    Anyway, she agreed to go with an onclick pop-up window for the informational feature and that was all good, but now she'd like it to display different pieces randomly so that she can update when she gets the chance, but people will still get a variety of these pieces. I see a problem with using a random quote kind of script, in that she'd have to edit an array or text file that's really meant to handle smaller bits of information and she's going to want to use quotation marks within these pieces and be able to use html for links. If anyone knows of a script that makes that fairly simple, it'd be great. Otherwise, I thought that a random link might be better. Then she can just edit the plain html pages that we set up for this and it would be a lot simpler. She doesn't really know html, btw, but just enough DW to use it for these things. So, what I'm wondering is can I combine a random link script with pop-up window code?

    If not, I'm certainly willing to listen to any suggestions that I can implement, not being any kind of programmer at all.

    Thanks for even reading this far down.

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi psalzer,

    why not randomize the url and send the result to the window.open()?
    That way the client can create whatever type of page she wants, and the link simply points to it.

    <a href="javascript:getLink()">goRandom</a>

    var links2Randomize = new Array();
    links2Randomize[0] = "http://members.aol.com/grassblad";
    links2Randomize[1] = "http://www.javascriptcity.com";
    links2Randomize[2] = "http://www.pageresource.com";

    function getLink()
    {
    randomURL = Math.floor(Math.random() * links2Randomize.length)
    var popUpWin = window.open(randomURL,"", features desired);
    }

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    SitePoint Guru
    Join Date
    Jul 2000
    Location
    Long Island, NY
    Posts
    755
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes! That's exactly what I want to do. I'm not sure I get exactly how, even with your example. When I use a javascript, I pretty much cut, paste, edit the variables and follow instructions. I'm going to work with the code, though. I'm just happy that it can be done. Thank you!

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi psalzer,

    Glad you like it. BTW: if you need to subcontract stuff to another NYer, send me an email ( grassblad@aol.com ) or contact me at the javascript forums.

    Just realized, the function should read as follows:

    function getLink()
    {
    randomNdx = Math.floor(Math.random() * links2Randomize.length)
    randomURL = links2Randomize[randomURL]
    var popUpWin = window.open(randomURL,"", features desired);
    }

    Vinny
    Last edited by Vincent Puglia; Aug 21, 2001 at 14:47.
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

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