Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Popup window with flexible size

I need to open a popup window which will be flexible in size. i.e. its height and width will be according to its document size. And the code should be in the main page. Is it possible?
0
Santanu
Asked:
Santanu
1 Solution
 
bjorsqCommented:
As far as I'm aware, this isn't possible. The problem lies in determining the size of the document loaded in the popup from the main window. It isn't a trivial task to determine the size of a document loaded in a window, and some documents will fit in a window by default (say if they consist of divs or tables with percentage widths set). Why not just make the popup resizeable and open it at a sensible size?

If the popup will just contain an image, then the task is a bit more straightforward, as you can access the width and height of the image quite easily:

var popWin = window.open('popup.html','popup','resizeable');
check = setTimeout("checkWin()",20);
function checkWin(){
  if(popWin.window.document.images[0]){
    clearTimeout(check);
    popWin.resizeTo(popWin.window.document.images[0].width,popWin.window.document.images[0].height);
    alert("width="+popWin.window.document.images[0].width+"\nheight="+popWin.window.document.images[0].height);
  }
}

This is just a quick example - I've tested it locally and it works, but I think the image needs to be loaded before you can access its dimensions, and I'm not sure if checking whether popWin.window.document.images[0] returns a true or false value will do this consistently.
 
0
 
SantanuAuthor Commented:
Thank you for your code. Its running well. But is there any process to get the div size or table size of a page which can be use to set the window size of that page.
0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bjorsq {http:#8032323}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now