0

I have a page that displays restaurant food menu. And when a person clicks on a particular food item I want to open the link in colorbox. Is there a way I can open the links in colorbox without effecting other anchor tags. I cannot modify the existing code(menu is displayed by 3rd party plugin) but I can add additional script to the page(jquery or php). So I was hoping to add ("a").click(), but I wasn't sure how to get the href link for a particular anchor tag. For now all the links I want to open have string "/restaurants/" in common. Any suggestions about how to solve this problem?

user899893
  • 307
  • 3
  • 8
  • 16
  • Try IFrames which you can make them look better and you can open them as you need it. – coder Jan 19 '12 at 21:04
  • I think this is what you need http://stackoverflow.com/questions/1383304/how-to-construct-a-url-to-open-a-page-with-jquery-lightbox-plugin-colorbox – coder Jan 19 '12 at 21:26
  • @DotNetter - both questions are colorbox related, but they're different questions. He just wants to add an on click event, and the question you linked to was about auto firing colorbox when visiting a certain url – Tom Jan 19 '12 at 21:39

1 Answers1

2
<script type="text/javascript">
  $(document).ready(function() {
    $("a", ".rest-menuitem").click(
      function(event) {
        event.preventDefault();
        var elementURL = $(this).attr("href");
        $.colorbox({iframe: true, href: elementURL, innerWidth: 645, innerHeight: 509});
      });
  });
</script>

Change innerWidth and innerHeight to fit your content

Tom
  • 3,450
  • 22
  • 31
  • I had two problems using the above code: 1) its been triggered for every anchor tag. 2) Actual colorbox is not pooping up. (http://delivery3.water-7.com/index.php/restaurants/manufacturers/3/Barcelona-Restaurant-&-Winebar/products). If you look at the page src the code is in lightbox.js – user899893 Jan 19 '12 at 22:33
  • I was able to limit the jquery event to required anchor tags. But I am not sure why the actual colorbox is not showing up – user899893 Jan 19 '12 at 22:49