views:

819

answers:

3

Hello.

I am not entirely sure if this is possible or not but so far you guys here at SO were always able to help me out so here it goes:

The following website: www.bgarchitect.co.nz

Has a navigation that works fine on the main page but (due to me making a mistake) does not work on the sub pages as it relies on images being loaded and then switching their hide() / show() properties. (it's quite easy to spot the mistake once you're on the site).

Is there any way that I could create a function that checks if the user is on the home page (http://www.bgarchitect.co.nz/index.php) and if NOT then goes to that page and upon loading automatically executes the funtion that is normally mapped to the navigational element being clicked?

Example: I am on a sub page and click on "Culture" then—since i am not on the home page—I am being taken back to the home page and the culture() function is being executed without me having to click the button again.

Thanks for reading. Jannis

PS: I know this is far from ideal in any case but I am trying not having to manually having to fix my mistakes throughout the entire site (which would take quite some time)..

+1  A: 

You could pass a parameter in the query string (eg go to index.php?run=culture), and on the main page have something that checks the querystring for this parameter, and executes the command required.

Probably worth fixing it properly if you're up for it however.

Chris
thanks for the reply. it kind of dawns of me that the only way to really work this out properly is fixing the root cause.. maybe i can use textedit to do a batch fix.. i ll have a look and see. Out of curiosity though: How do you instruct jQuery to goto a URL?
Jannis
You wouldn't get jquery to go to a url, all you need is a simple <a href=...> link. If you really want to javascript it, do: window.location.href = 'newpage.html';
Chris
or, in your case: window.location.href = 'index.php?run=culture';
Chris
Thank you very much. i had looked for a technique to do exactly that (for a different project) but couldn't find a solution then. Now i know.so is the syntax [document.extension]?run=[functionName] ?
Jannis
Yes, but remember in the target page, you need to write your own Jquery that'll check the 'run' query variable and run the appropriate function.
Chris
okay. thanks again.
Jannis
A: 

Generally, I'd suggest you fix the real cause of the problem instead of hacking around it. If you can work out a good solution you're likely to be in pain every time you have to make new changes in the future.

Given that you already update all your links when the page loads through jQuery, seems like you should be able to find a way to update them correctly based on what page your on, instead of your load a page, then call a function idea.

If you aren't going to solve the root problem, I'd suggest fixing it with redirects in the PHP code, instead of in JS.

acrosman
thanks. i am still quite the php and jquery amateur so this project/website is as much about me learning these things as it is about doing it all properly. That being said. I'll see if I can batch fix this in a texteditor first, could you perhaps elaborate on the PHP you suggested? Thanks again.
Jannis
A: 

Find and replace is your friend. There's plenty of IDE/text editors out there that can do this across multiple files.

DaRKoN_