Basic Javascript scenario: best practice??

Discussion in 'Javascript' started by bj, Apr 15, 2004.

  1. bj

    bj Guest

    I have several pages that I want to allow the same kind of activity,
    so my basic question is how best to structure the interaction (and I
    have one related subquestion as well).

    Scenario: The user clicks a hyperlink and opens a new window in which
    there is a bit of explanatory text. This text will be different for
    every link. In addition, there is an image on the page which can be
    clicked to close the new window.

    (This image should rollover on mousing over and out of the image: I
    haen't been able to make this work yet; help?)

    I would like to pass the text, and the necessary window size (just big
    enough for the text)to be used to a common function that I can use
    over and over again by calling that function when the user clicks the
    link. And I need to be able to have the Close image have rollover
    capability when the new window opens.

    I don't want to creat an html doc for this and call it if that is at
    all possible.

    The code I have used is below, but it's too clunky and cannot be
    reused easily:

    function rollImages(){
    if (document.images){
    changeClose = new Image;
    simpleClose = new Image;
    changeClose.src = "../../../../../Generic_Images/close_over_v2.gif";
    simpleClose.src = "../../../../../Generic_Images/close_v2.gif";
    if (card.Close.src = "../../../../../Generic_Images/close_v2.gif"){
    alert("I see it");

    //card.Close.src =
    "../../../../../Generic_Images/close_over_v2.gif";
    }
    //else{card.Close.src =
    "../../../../../Generic_Images/close_v2.gif";}
    }
    else {
    changeClose = "";
    simpleClose = "";
    document.Close = "";
    }
    }

    function newCardWindow(){

    cardHolder=window.open("", "card",
    "resizable=no,width=250,height=110")

    cardHolder.document.write("<html><head><title>Who is the card
    holder?<\/title><\/head><body bgcolor=\"#ffffff\"
    style=\"font-family:arial;\"><p>This is the person to whom the card
    was officially issued during the enrollment process.<\/p><div
    style=\"background-color:#00005e; bottom:0%; height:20px;
    position:absolute; width:100%;\"><a onClick=\"window.close()\"
    onKeyPress=\"window.close()\" id=\"CloseButtonLink\" tabindex=\"1\"
    onmouseover=\"opener.rollImages()\" onmouseout=\"opener.rollImages\"
    tabindex=\"1\"><div style=\"position: absolute; text-align: center;
    width: 100%;\"><img src=\"..\/..\/..\/..\/..\/Generic_Images\/close_v2.gif\"
    alt=\"Close Window\" name=\"Close\" id=\"Close\" width=\"66\"
    height=\"20\" border=\"0\" ><\/div><\/a><\/div><\/body><\/html>")

    }


    down in the html the functions are called this way

    <li>Color photo of the <a href="javascript:newCardWindow()">card
    holder</a></li>
     
    bj, Apr 15, 2004
    #1
    1. Advertising

  2. bj wrote:
    > I have several pages that I want to allow the same kind of activity,
    > so my basic question is how best to structure the interaction (and I
    > have one related subquestion as well).
    >
    > Scenario: The user clicks a hyperlink and opens a new window
    > in which there is a bit of explanatory text.


    In a world where pop-up blocking is common that is an optimistic
    statement.

    > This text will be different for
    > every link.


    Hypertext.

    > In addition, there is an image on the page which can be
    > clicked to close the new window.


    Your users don't know how to close a window?

    > (This image should rollover on mousing over and out of the image: I
    > haen't been able to make this work yet; help?)
    >
    > I would like to pass the text,

    <snip>

    So you want to have all of the source HTML for each of the pop-ups on
    the same page as the links? But then you want to wrap it in Javascript
    so that it is completely inaccessible to users with javascript disabled
    (and browsers that do not support window.open, along with the people
    using pop-up blockers.).

    I would say forget about the new window and put the text contents in the
    HTML, and then use javascript to manipulate that HTML so it acts like a
    pop-up (but doesn't risk falling fowl of pop-up blockers). Have a look
    at:-

    <URL:
    http://www.litotes.demon.co.uk/example_scripts/multiWindow_1.html >

    - the last link in the list was added for you (the rest is a response to
    a question form last week). And while you are there check out the link
    that disables the javascript, demonstrating how you can have your pop-up
    effect and still create a system that can be used by anyone with any
    browser (javascript capable or not).

    Richard.
     
    Richard Cornford, Apr 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nemisis
    Replies:
    1
    Views:
    517
    Mark Rae
    Apr 4, 2007
  2. Alex Ayzin

    Best way to implement security scenario

    Alex Ayzin, Nov 16, 2004, in forum: ASP .Net Security
    Replies:
    3
    Views:
    160
    Ken Schaefer
    Nov 23, 2004
  3. bj
    Replies:
    0
    Views:
    117
  4. Tim Streater

    Best program to practice with JavaScript

    Tim Streater, Oct 29, 2007, in forum: Javascript
    Replies:
    6
    Views:
    651
    beegee
    Oct 30, 2007
  5. oldyork90
    Replies:
    1
    Views:
    168
    Jeremy J Starcher
    Sep 10, 2008
Loading...

Share This Page