By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Executing code within a hyperlink

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
eric rudolph wrote:
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?


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
Jul 17 '05 #2

P: n/a
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
http://ppewww.ph.gla.ac.uk/~flavell/...4/results.html
http://jibbering.com/2002/4/httprequest.html
http://en.wikipedia.org/wiki/AJAX
++++
@todo Better question. Someone may help.

Jul 17 '05 #3

P: n/a
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://ppewww.ph.gla.ac.uk/~flavell/www/status204/
http://www.faqs.org/rfcs/rfc2616.html
http://www.php.net/header
http://jibbering.com/2002/4/httprequest.html
http://en.wikipedia.org/wiki/AJAX
++++
@revision 1 Initial
@revision 2 Reworded for clarity. More links
@todo Better question. Someone may help.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.