Issue
I’m planning on making a lightbox-like project page. I want to have it where the user clicks on an image and it brings up a div that contains a article with paragraphs, images, and whatever else I want to put in it. It will basically be a scrollable article that hovers over the original page which the user can close to see the project page again. I’d prefer to not force the user to download every article when they enter the gallery page.
Request
Is there a way to pull a small article like this from say, an html file stored on the server? Is there a better way to approach this problem?
-edit- I’d prefer to not use jQuery or any other javascript library. This website will be presented to a Javascript course, so I would like it all to be normal javascript code. Besides, I’d would rather learn how jQuery does it than use use it blindly.
Thanks in advance!
Here’s a simple lightbox in pure JavaScript, loading its content from a specified URL. It doesn’t handle errors gracefully and if it works in IE, it’s only in newer versions.
Since it is taking the HTML of the target page and inserting it into your document directly, it might behave oddly if the URL points to a complete HTML page. It would work best if the URL only points to an HTML snippet (no
<html>or<body>tags).Mozilla’s AJAX tutorial may be of use to you as well.