View Full Version : Javascript if... statement.

09-16-2011, 08:28 PM
I'm very new to javascript in general, but here's what I'm looking to do:

I have a navigation link ("galleries") that 'onclick' displays a sub-menu of other links (the specific galleries).
This is on the home page of my site.
When a user first views the home page, the sub-menu does not display, until they click "galleries".

On other pages of my site, the "galleries" link is one of the options in my navigation. That link takes users back to the home page which is what I want it to do.
But what I'm looking for to happen is if the user is directed back to the home page from within another page on my site, I'd like the link on the homepage to automatically display the sublinks under the "gallery" link.
This is so that users don't have to click "galleries" twice in order to see the submenu.

For example: If a user is on the 'about me' page, in the navigation there is a 'galleries' link. If they click it, it takes them to the home page. They would then have to click on 'galleries' again on the home page in order to display the sub-menu of individual galleries.
I want them to show up immediately, but only when directed back to the home page from within my site.

I think I do that with an 'if' statement, but I'm not sure of the syntax.
I know that's a bit wordy and a little round about but I hope you can understand what I mean. Feel free to ask any questions if I can clarify something for you.

09-16-2011, 11:43 PM
it's probably quite doable, although you'd need to specify how the pages navigate between each other and what triggers the menu opening.

probably easier if you provide a link to your page, really...

09-17-2011, 12:50 AM
if(document.referrer.indexOf('YOUR SITE') && document.referrer != 'YOUR HOME PAGE'){
//Code that expands galleries

Fill in the blanks.

09-19-2011, 03:06 AM
Perfect! Thank you so much!