Executing code within a hyperlink

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eric rudolph

    #1

    Executing code within a hyperlink

    I am writing a photo gallery and suppose 8 photos are displayed. When the
    user clicks on a button under the picture, I want it to add that picture
    name to a "favorites" list within the session data, but NOT leave the page
    the user is on. How could I do this?

    thanks


  • Nicholas Sherlock

    #2
    Re: Executing code within a hyperlink

    eric rudolph wrote:[color=blue]
    > I am writing a photo gallery and suppose 8 photos are displayed. When the
    > user clicks on a button under the picture, I want it to add that picture
    > name to a "favorites" list within the session data, but NOT leave the page
    > the user is on. How could I do this?[/color]

    You could put an invisible IFrame on the page. The link targets the
    IFrame, which gets your server to add it to the session, without the
    user's browser navigating away from the page.

    Cheers,
    Nicholas Sherlock

    Comment

    • R. Rajesh Jeba Anbiah

      #3
      [FAQ] How can I process a link/form without allowing the page to refresh or reload? (Was Re: Executing code within a hyperlink)

      Q: How can I process a link/form without allowing the page to refresh
      or reload?
      A:
      1. Using PHP alone:
      Send a header status with 204
      2. IFRAME hack:
      POST or link the request to the invisible IFRAME. Need to name the
      IFRAME and use it for "target"ing .
      3. JavaScript:
      Use XMLHttpRequest object and preferably with AJAX technique.

      Caveats:
      (1) Status 204 is not supported in older browsers
      (2) is kind of dirty hack that breaks browser's back button
      (3) totally breaks accessibility criteria

      Refer:
      http://www.sitepoint.com/print/no-refresh-links





      ++++
      @todo Better question. Someone may help.

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        [FAQ] How can I process a link/form without allowing the page to refresh or reload?

        Q: How can I process a link/form without allowing the page to refresh
        or reload?
        A:
        1. Using PHP alone:
        Send a HTTP header status with 204
        2. IFRAME hack:
        POST or link the request to the invisible IFRAME. Need to name the
        IFRAME and use it for "target"ing .
        3. JavaScript:
        Use XMLHttpRequest object and preferably with AJAX technique.

        Caveats:
        (1) breaks usability (especially without JavaScript alert) as it is de
        facto to expect results after clicking the link or submitting the form.
        Also, HTTP Status 204 is not supported in few older browsers.
        (2) is kind of dirty hack that breaks browser's back button
        (3) totally breaks accessibility criteria

        Refer:
        http://www.sitepoint.com/print/no-refresh-links

        http://www.faqs.org/rfcs/rfc2616.html





        ++++
        @revision 1 Initial
        @revision 2 Reworded for clarity. More links
        @todo Better question. Someone may help.

        Comment

        Working...