admin管理员组

文章数量:1415664

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 mon. Any suggestions about how to solve this problem?

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 mon. Any suggestions about how to solve this problem?

Share Improve this question asked Jan 19, 2012 at 21:02 user899893user899893 3073 gold badges8 silver badges16 bronze badges 3
  • Try IFrames which you can make them look better and you can open them as you need it. – coder Commented Jan 19, 2012 at 21:04
  • I think this is what you need stackoverflow./questions/1383304/… – coder Commented Jan 19, 2012 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 Commented Jan 19, 2012 at 21:39
Add a ment  | 

1 Answer 1

Reset to default 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

本文标签: javascriptopen url in jquery colorboxlightboxStack Overflow