2014-12-17 1 views
-1

안녕하세요 저는 완벽한 크기의 이미지를 html 팝업으로 만들려고 노력하고 있지만 두 번째에만 작동합니다.window.open image resize jquery

예를 들어 이미지를 클릭하면 이미지가 완벽한 크기로 열리고 닫아서 다시 열면 작동합니다.

내 코드 디버깅하십시오

$(function() { 
    $("a.popup3").click(function(){ 

     var asrc = $(this).attr("href"); 

     var image = new Image(); 
     image.src = asrc; 

     window.open(image.src,"Image","width="+image.width+",height="+image.height); 
     alert(image.src+"adfaSDF"+image.width); 

     return false; 
    }); 
}); 

을하고, HTML과 같은 것입니다 :

<a class="popup3" href="http://localhost/wp/wp-content/uploads/2014/12/Eccles_leaving.jpg"> 
    <img class="alignnone wp-image-196" src="http://localhost/wp/wp-content/uploads/2014/12/Eccles_leaving-300x200.jpg" alt="Eccles_leaving" width="220" height="147"> 
</a> 

답변

2

시도는로드 기능의 내부 창을 엽니 다,

$(function() { 
    $("a.popup3").click(function(){ 
     var asrc = $(this).attr("href"); 
     var image = new Image(); 
     image.src = asrc; 
     image.onload = function() { 
      window.open(image.src,"Image","width="+image.width+",height="+image.height); 
     }; 
     return false; 
    }); 
}); 
+1

감사의 친구를, 그 일했다! –