이미지가있는 팝업 창을 만들려고하고 있는데 팝업이 이미지와 동일한 종횡비로 나타나길 원합니다. 그러나 나는 image.onload의 이미지 크기만을 알고 있습니다. 그래서 필요한 것은 image.onload 다음에 오는 팝업입니다. 그러나 브라우저는이를 원치 않는 팝업으로보고 차단합니다. 사용자 클릭 후 유일한 팝업 인 경우에도 마찬가지입니다.이미지 업로드 후 팝업
나는 팝업을 먼저 만들고 나중에 내용과 크기를 변경하려고했지만 때로는 작동 할 때도 팝업 창이 다시 배경에 숨길 수 없게됩니다 (Windows의 크롬)
지연된 팝업이 여전히 사용자의 클릭에 hooked
인지 확인하는 방법이 있습니까? 또는 다른 제안 사항.
내가하고 싶은 코드 작업 :
selectURL: function(url) {
// Check for images, otherwise just simply open the file by the browser.
if(url.match(/(jpe?g|png|gif|bmp)$/gim)) {
// Check if colorbox exists and use if so.
if($.colorbox) {
$.colorbox({
maxWidth:'80%',
maxHeight:'80%',
fixed: true,
scrolling: false,
href: url,
open: true,
photo: true
});
} else {
// New image object so we can calculate the required popup size on load
var myImage = new Image();
myImage.src = url;
// Close current window to make sure focus works
if(typeof(popupWindow) !== 'undefined') {
popupWindow.close();
}
// Temporary loading image
popupWindow = window.open('/images/loading.gif','popupWindow','height=400,width=600,resizable=no,scrollbars=no,top=200,left=200');
if (window.focus) {
popupWindow.focus();
}
// Calculator and actual image opener :)
myImage.onload = function() {
var maxWidth = 600,
maxHeight = 600;
// Close existing popup
if(typeof(popupWindow) !== 'undefined') {
popupWindow.close();
}
if(this.width < maxWidth && this.height < maxHeight) {
popupWindow = window.open(this.src,'popupWindow','height='+this.height+',width='+this.width+',resizable=no,scrollbars=no,top=200,left=200');
} else if(this.width === this.height) {
popupWindow = window.open(this.src,'popupWindow','height='+maxHeight+',width='+maxWidth+',resizable=yes,scrollbars=yes,top=200,left=200');
} else if(this.width < this.height) {
popupWindow = window.open(this.src,'popupWindow','height='+maxHeight+',width='+(maxHeight/this.height * this.width)+',resizable=yes,scrollbars=yes,top=200,left=200');
} else {
popupWindow = window.open(this.src,'popupWindow','height='+(maxWidth/this.width * this.height)+',width='+maxWidth+',resizable=yes,scrollbars=yes,top=200,left=200');
}
if (window.focus) {
popupWindow.focus();
}
}
}
} else {
window.open(url);
}
}
로딩 이미지를 처음 만들지 않아도 문제가 해결되지 않습니다. 두 번째 팝업에 관한 것이 아니라 이미지에 관한 것입니다.로드. 그건 제쳐두고, 나는 이미지를 여는 다른 파일 안에 이미지 로딩 스크립트를 두려고 생각하지만 모든 브라우저에서 window.resizeTo가 해당 창에서 제대로 작동하는지 확인하고 있습니까? –
다른 브라우저에서'resizeTo' 또는'moveTo'를 사용 해본 경험이별로 없지만 테스트 해보기로 남겨두고 있습니다. 예를 들어 제가 작성한 예제로 방금 답을 편집 했으니까요. 다른 방법으로 도와 줄 수 있다면 알려주세요. – Spooky
몇 가지 테스트를 한 후 URL 막대가 이미지를 약간 덮어도 내 예제에서는 팝업 크기가 이미지의 크기로 조정되는 것으로 나타났습니다. 이 방식이 마음에 들지 않으면 크기로 채우기를 추가하거나 클라이언트 영역을 찾아서 창 영역에서 빼기를 원할 수 있습니다. 그러면 각 방향으로 얼마나 많이 넣어야하는지 확인할 수 있습니다. – Spooky