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
Prem Anandh
331 gold badge2 silver badges9 bronze badges
-
You should pass the img src to pop window.vijaykumar– vijaykumar2013年10月26日 07:01:32 +00:00Commented Oct 26, 2013 at 7:01
-
1without code nobody can help youRakesh Shetty– Rakesh Shetty2013年10月26日 07:04:51 +00:00Commented Oct 26, 2013 at 7:04
-
Show some code and a jsfiddle if you can.user762330– user7623302013年10月26日 07:08:42 +00:00Commented 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>Prem Anandh– Prem Anandh2013年10月26日 07:09:28 +00:00Commented 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 jqueryPrem Anandh– Prem Anandh2013年10月26日 07:09:54 +00:00Commented Oct 26, 2013 at 7:09
2 Answers 2
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
writeToBhuwan
3,28111 gold badges43 silver badges67 bronze badges
Sign up to request clarification or add additional context in comments.
6 Comments
Prem Anandh
but i have 10 images each image id is same.
writeToBhuwan
You are going against the rule of HTML.. A page should have unique element ID's.
writeToBhuwan
you have to fetch the elements by class, not by ID. Assign the same class "yourImageClass" to every element and run the above code
Prem Anandh
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>
Prem Anandh
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
|
$("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
Amol Navsupe
1731 silver badge11 bronze badges
Comments
lang-js