views:

166

answers:

1

I have a web page with a off-site links whose onclick events are handled by jQuery. The jQuery fetches the content of the page the link points to and inserts it into a div.

What I would like to do is be able to give somebody an url for this page that would cause the onclick event for one of the links to fire, thus loading the div with the remote page.

For example, say my page has the following markup:

<a class=link href=yahoo.com>yahoo</a>
<a class=link href=bekko.com>bekko</a>
<div id=div_where_remote_html_is_loaded></div>

...and jQuery code like:

$('a.link').click(function(){
  //code fetches remote html and adds to div
  }

Is it possible to specify an url to this page that would also cause the onclick event to fire for one of the links?

+1  A: 

You could add an id to your links and use it as a hash on the url you want to give ..

then use javascript to target the link in your page..

<a class=link href=yahoo.com id="link1">yahoo</a>
<a class=link href=bekko.com id="link2">bekko</a>
<div id=div_where_remote_html_is_loaded></div>

and after you assign the click event with your code add

$('#' + location.hash ).click();

The link you would give now would be the normal url with a #link1 at the end for the first link, like http://somedomain.ext/yourpage.htm#link1 ..

Gaby
Perfect! Sorry for the slow reply.