Jump to content

Open a window ontop of current browser to select an image


james909

Recommended Posts

When I click an image I am trying to get another window to open (500px by 500px) which can be scrolled down, that sits on top of the current browser screen, which displays multiple images (that are 50px by 50px), when one of these images is clicked it sets a javascript global variable in the current browser screen as that image name, and changes the image that was originally clicked in the current browser to the new image.

 

Can anyone supply any sample code of how I would achieve this

Link to comment
Share on other sites

You'd be better off, and it'd be easier to code, using a div overlay as your window. There are a number of libraries out there to create modal dialogs using div overlays, jQuery UI's dialog is a common one and easy to use. Combine that with some ajax to load your image list and display it.

 

function promptForImage(cb){
   var dlg = $('<div>');
   dlg.on('click', 'img', function(e){
      cb(this.src);
      dlg.dialog('close');
   }).load('image_list.html').dialog({
      modal: true
      , width: 500
      , height: 500
      , autoOpen: true
   });
}

promptForImage(function(img){
   alert('You selected image: '+img);
});
Just as a sample. image_list.html would just be a page with a bunch of <img> tags. When an image is clicked it will show you the source of the image selected by using the callback function provided when calling promptForImage.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.