I would like to link to one of the blocks that are using the content switch script and have that block opened. Does anyone know a way to do this?
I would like to link to one of the blocks that are using the content switch script and have that block opened. Does anyone know a way to do this?
OK, first you need to set the:
at the beginning of the script. Next, replace the current 'do_onload()' function with this one:Code:var enablepersist="off"
That's it for the script. Now to call the page with the switch content script on it and have a specific item open, use this syntax for the link on the calling page:Code:function do_onload(){ uniqueidn=window.location.pathname+"firsttimeload" var alltags=document.all? document.all : document.getElementsByTagName("*") ccollect=getElementbyClass(alltags, "switchcontent") statecollect=getElementbyClass(alltags, "showstate") if (enablepersist=="on" && ccollect.length>0){ document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load if (!firsttimeload) revivecontent() } if (ccollect.length>0 && statecollect.length>0) revivestatus() if (unescape(location.href).indexOf('?sc=')!==-1){ var spantags=document.getElementsByTagName("SPAN") var showstateobj=getElementbyClass(spantags, "showstate") var scNum=unescape(location.href).substr(unescape(location.href).indexOf('?sc=')+4) expandcontent(showstateobj[Math.abs(scNum)-1].parentNode, 'sc'+scNum) } }
This will open the 2nd item where 'switch_link.htm' is the name of the page with the switch content script on it. Just change the number 2 to whatever number item you want. The text in green can be whatever you want.Code:<a href="switch_link.htm?sc=2">Switch #2 Open</a>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
If the block is on the same page as the link, it would seem easier to just do this as a link
If you're linking remotely, then you probably want to do what he said above, but it seems very roundabout if it's on the same page.Code:<a href="#" onClick="expandcontent(this, 'sc2')" >Link text here</a>
Nope, that won't work because 'this' is no longer the header. If the OP really wants just that, there is a way though.Originally Posted by anonymouse
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
hmmm...I used that to make extra close links at the end of the divs, so I assumed it would work to open.
Hmmmm, indeed, anonymouse. It will toggle the open/closed state of the element with id of sc2 but, if free standing on the page, will not change the plus to a minus or vise/versa. This assumes that you are using the 'state symbols'. Another issue is, if you have a stand alone link on a page to open an id'd element, what should happen if it already is open? What should happen if they are all already open, some including or not including the selected one open? My choice was to just have everything close and the selected one be opened. Still, if that was the situation when the linked was clicked, it looks like nothing happened. There really doesn't seem to be a way to reconcile 'a link to open one block' with having the state of the page change when it is clicked, in every possible situation. If we set it to toggle, then the page state is guaranteed to change when it is clicked but, it is no longer simply 'a link to open one block'.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
John-
Thanks for your help! I am linking from a remote page. I tried altering the script as you suggested but it didn't seem to work. The page with the script showed every link open and I lost the expand/contract functionality.
Maybe it would help if I gave a better description for what I am doing. On my default page I have several news stories that include just a snippet of the full story plus a link to the full story. This is where I am linking from. Typically there would only be 3-4 stories on this page.
The actual stories & script are on a separate page, with the titles as links. This page will hold the stories from the front page as well as older articles.
Having all the links closed on load is not a big issue, but I do need the page(script) to function like the original when someone goes directly to the page. I am using graphics for the open/close symbols if that makes a difference. I also use the expand /contract all feature.
The goal, of course, is to have the link go directly to the (expanded) story as opposed to the full list.
Not a necessity, just trying to do whatever I can to help the "average user".
Hmm, it worked here and sounds from your description like it should work in your situation, unless you are not using the default structure for your page with the script on it, you missed something in my instructions, or I goofed somehow in explaining the needed changes. How about:
PLEASE: Include the URL to your problematic webpage that you want help with.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Oh, here is a demo Linker Page and here is the Page Itself, which also includes an on page link for expanding content. Right click on them to view their source. I've included error checking routines not in the original code I posted, which should make the HTML markup more tolerant of customization.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
John-
It's absolutely perfect! Thanks so much! The site is under development at the moment and password protected at the clients request, so I really can't post it here. If you want to see it, just send me an email and I will give you temporary access.
Bookmarks