c_shelswell Posted January 30, 2007 Share Posted January 30, 2007 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 shownfunction 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 fantasticThanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.