0

In my program I used image pop up window. some what images scrolling in home page.

While I click on the image in the sense the pop up will open and show the particular image in popup windows. How I can show the image in pop up window. Now I got the pop up window but I can't show the image in the popup window.

Here is my code so far:

$("img").click(function(){
 var $dialog = $('<div></div>') 
 .html(' <img src="localhost:81/keprandemo/media/catalog/product/cache/1/...; width="200" height="200" alt="Milk(1 lit)">') 
 .dialog({ autoOpen: true, resizable: false, draggable: false, width: 600, height:600, modal: true, title: 'Create Your Own PopUp Window' }); }); 
halfer
20.2k20 gold badges111 silver badges208 bronze badges
asked Oct 26, 2013 at 6:59
6
  • You should pass the img src to pop window. Commented Oct 26, 2013 at 7:01
  • 1
    without code nobody can help you Commented Oct 26, 2013 at 7:04
  • Show some code and a jsfiddle if you can. Commented Oct 26, 2013 at 7:08
  • $("img").click(function(){ var $dialog = $('<div></div>') .html(' <img src="localhost:81/keprandemo/media/catalog/product/cache/1/…" width="200" height="200" alt="Milk(1 lit)">') .dialog({ autoOpen: true, resizable: false, draggable: false, width: 600, height:600, modal: true, title: 'Create Your Own PopUp Window' }); }); </script> Commented Oct 26, 2013 at 7:09
  • i pass the img src directly but i want dynamically. which image i choose that image url i want to get and display in jquery Commented Oct 26, 2013 at 7:09

2 Answers 2

1
var ImageSource="";
$('.yourImageClass').click(function(){
 ImageSource=$(this).attr('src');
});

//Pass this ImageSource to your image window

EDIT:

$("img").click(function(){
 var source=$(this).attr('src');
 var $dialog = $('<div></div>') 
 .html('<img src="'+source+'" width="200" height="200" alt="Milk(1 lit)">') 
 .dialog({ autoOpen: true, resizable: false, draggable: false, width: 600, height:600, modal: true, title: 'Create Your Own PopUp Window' }); 
}); 

This code should do the trick.!

answered Oct 26, 2013 at 7:12
Sign up to request clarification or add additional context in comments.

6 Comments

but i have 10 images each image id is same.
You are going against the rule of HTML.. A page should have unique element ID's.
you have to fetch the elements by class, not by ID. Assign the same class "yourImageClass" to every element and run the above code
another one problem. <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(170) ?>" width="151" height="140" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /> <span class="productname"> <!-- kepran changes removed product redirect url --> <a href="<?php echo $this->getUrl($_product->getUrlPath())?>" > <?php echo $_product->getName(); ?></a> </span>
if once i click the image i get the image source. at the same time i want to get the image name and the price
|
0
 $("img").click(function(){
 var $dialog = $('<div id="urID"></div>') 
 .dialog({ autoOpen: true, resizable: false, draggable: false, width: 600, height:600, modal: true, title: 'Create Your Own PopUp Window' });
 //ur div id name.
 $('#urID').html('<img src="localhost:81/keprandemo/media/catalog/product/cache/1/...; width="200" height="200" alt="Milk(1 lit)">');
 }); 
answered Oct 26, 2013 at 7:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.