1

I used the toggle tutorial from here http://www.sohtanaka.com/web-design/easy-toggle-jquery-tutorial and came up with this website.

There is only 1 toggle link on the website.

My problem is, I have a html newsletter where a link needs to be placed and when it is clicked, it will go to the website and automatically focuses on the toggle link. The toggle link also should be automatically opened without clicking on it.

How can I achieve this?

doodoodukes
  • 148
  • 3
  • 12

1 Answers1

3

The link in your HTML newsletter should contain a query string or hash on the link, like so:

http://publicis-malaysia.com/ipad2/index.html?autofocus

or

http://publicis-malaysia.com/ipad2/index.html#autofocus

And then you can detect this in jQuery code:

    if (location.hash.indexOf('autofocus') > -1) {
        $('.trigger').click();
    }

This will check for 'autofocus' in the document hash when the page is opened, and then click the element. If you want to use the querystring ("?autofocus"), you should use 'search' instead of 'hash' in the first line of the example code.

You can put the code right after the code you took from the tutorial, in the script block in the head.

Gijs
  • 5,201
  • 1
  • 27
  • 42
  • okay another question tho, how do you make it so that when the link is clicked, the webpage opens and it focuses on the triggered toggle? – doodoodukes May 16 '11 at 05:46
  • Check out: http://stackoverflow.com/questions/68165/javascript-to-scroll-long-page-to-div :-) – Gijs May 16 '11 at 12:22