Jump to content

Stuck with a popup box turning on and off


c_shelswell

Recommended Posts

Hi i'm not too hot with javascript but in making a webpage for a friend i've had to try and get myself into it a little. Sadly with not quite as much joy as i was hoping.

I've got  a page with a load of links on it when you click one it should open up a little box with a "download now" bit of text in it which is coming from a seperate html file. The problem i have is that when you click on link it's fine and brings up the window but when you click the next link it should close the previous one and bring up the new one. I found a page with some code that looked about right that i tried to crib here' smy cribbed version
[code]/* Script by: www.jtricks.com
* Version: 20060314
* Latest version:
* www.jtricks.com/javascript/window/box.html
*/
// Moves the box object to be directly beneath an object.
function move_box(an, box,link, track, cut)
{
    var cleft = 57.5;
    var ctop = 11;
   
wimpy_loadAndPlay(link, track, cut, '', '');

box.style.left = cleft + 'em';
    box.style.top = ctop + 'em';
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_box(an, id, url, track, cut)
{

    var href = an;
    var boxdiv = document.getElementById(href);
var link = url;

if (href == "")
    {
   
        // Hide currently shown box.
        boxdiv.style.display='none';
        return false;
    }
    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    //boxdiv.setAttribute('id', href);

    //boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = '175px';
    boxdiv.style.height = '50px';
    boxdiv.style.border = '0px solid #fff';
    boxdiv.style.textAlign = 'justify';
    boxdiv.style.padding = '0';
    boxdiv.style.background = 'none';
    document.body.appendChild(boxdiv);

    var offset = 0;

    /*// Remove the following code if 'Close' hyperlink
    // is not needed.
    var close_href = document.createElement('a');
    close_href.href = 'javascript:void(0);';
    close_href.onclick = function()
        { show_hide_box(an, width, height, borderStyle); }
    close_href.appendChild(document.createTextNode('Close'));
    boxdiv.appendChild(close_href);
    offset = close_href.offsetHeight;
    // End of 'Close' hyperlink code.*/

    var contents = document.createElement('iframe');
    //contents.scrolling = 'no';
    contents.overflowX = 'hidden';
    contents.overflowY = 'scroll';
    contents.frameBorder = '0';
    contents.style.width = '100px';
    contents.style.height = ('100' - offset) + 'px';

    boxdiv.appendChild(contents);

 

    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(
            href+id);
           
    else
        contents.src = href+id;
        move_box(an, boxdiv, link, track, cut);

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    href = "";
    return false;
   
}[/code]

I just need a way to get the box on on click one then off if the user clicks on another link i'm just not at all good with javascript if anyone has any idea's that'd be fantastic

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.