|
|
|
|
![]() ![]() |
Sep 23 2005, 06:36 PM
Post
#11
|
|
|
Member [ Level 1 ] Group: Members Posts: 40 Joined: 24-July 05 Member No.: 7,405 |
I’ve tried to get this to work – but… I have two problems. The first is in this script:
CODE current=document.getElementById("index"); function change( item ) { element=document.getElementById(item); current.style.display="none"; element.style.display="block"; current = element; } What should I put instead of “item”? Should I write “div” or something like that? Also, I can’t really this script to work: CODE <span onclick="change('guestbook');">Guestbook</span> The “button” shows up as plain text. I’ve tried looking for reference on different coding sites, but I can’t find the answer. Can you help me? |
|
|
|
Mar 15 2006, 09:17 PM
Post
#12
|
|
|
Wheeeeeeee! Group: Members Posts: 245 Joined: 19-October 05 From: DG, Belgium Member No.: 9,200 |
Well, DigitalDingo doesn't seem to be hosted anymore, but just in case that someone else reads this topic afterwards:
It is a very bad idea to change site content using Javascript, because there are a lot of users with JS turned off or not even integrated, who would not be able to view your site properly. Also the function document.getElementById is not supported by all the old browsers, there are two alternatives: document.all (old Microsoft Internet Explorers) and document.layers (old Netscape browsers). So do yourself a favor and don't rely on JS for such essential things as showing and hiding content. If you do, then be sure to do it so, that the site is still viewable for those who don't have the JS support. In this case for example you could do it like this: CODE <div id="firstpage"><a name="first">...</a></div> <div id="secondpage"><a name="second">...</a></div> <div id="thirdpage"><a name="third">...</a></div> and then you can dynamically hide the layers onLoad (be sure to set it up so that you use the DOM-model, the IE-model and the Netscape-model (getElementById, all, layers) to provide maximum compatibility. Btw. if you're worried that your index file might get to big, but you totally don't want to reload a page (which is stupid I think, but well.. there might be good reasons for this), you can make use of the AJAX-code (JS communicates with the server and gets the new content when it needs it. AJAX tends to get more widely supported, but it's still quite new! CODE current=document.getElementById("index"); function change( item ) { element=document.getElementById(item); current.style.display="none"; element.style.display="block"; current = element; } What should I put instead of “item”? Should I write “div” or something like that? Oh and if you, DigitalDingo, are still wondering what to put for item, the correct syntax would be to call the function change, the following way: CODE <a href="java script:change('the_id_of_the_element_you_want_to_show')">Show Second Page, hide old Page</a> Get it? Remember that's not so great code, if you really intend using something like this, post back and we can work something out. |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 22nd November 2008 - 10:10 PM |