Solved

Open a auto sizeable window

Posted on 2006-11-13
5
194 Views
Last Modified: 2010-05-18
I've got a page with an ASP datagrid on it that currently opens in a pop-up using a script.
What I want to do is size this window based on the size of the datagrid. I've been able to do this
with images in the past, but i haven't been able to get the code to work for the datagrid.
How would I do this?


TIA
0
Comment
Question by:mwmiller78
5 Comments
 
LVL 8

Expert Comment

by:RozanaZ
ID: 17930978
0
 

Author Comment

by:mwmiller78
ID: 17931060
that looks like a great way to open a 400 x 400 window. can you answer my question?
0
 
LVL 6

Expert Comment

by:system_down
ID: 17931097
<html>
<head>
<script type="text/javascript">

function open_win(h,w)
{
window.open("http://www.w3schools.com","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width="+w+", height="+h+")
}
</script>
</head>

<body>
<form>
<input type="button" value="Open Window" onclick="open_win("+datagrid.height+","+datagrid.width+")">
</form>
</body>

</html>

0
 
LVL 8

Expert Comment

by:RozanaZ
ID: 17931149
Ok, if you have dynamic datagrid dimensions:

<html>
<head>
<script type="text/javascript">
function open_win()
{
  winObj = window.open("2.html","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
  winWidth = winObj.document.getElementById("test1").width;
  winHeight = winObj.document.getElementById("test1").height;
  winObj.resizeTo(winWidth,winHeight);
}
</script>
</head>

<body>
<form>
<input type="button" value="Open Window" onclick="open_win()">
</form>
</body>

</html>


Where 'test1' is id of your datagrid.
0
 
LVL 17

Accepted Solution

by:
gops1 earned 500 total points
ID: 17936648
Here is sample script which you can try out:
 
Code for the Parent Window:
==================

<html>
      <head>
            <title>Script Demo</title>
            <script language="JavaScript">
                  function openWin(){
                        var child=window.open("Q_22058597-child.html","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes");
                  }
            </script>
      </head>
<body>
      <a href="#" onclick="openWin();return false;">Open Child</a>
</body>
</html>



Code for the Child:
============

<html>
      <head>
            <title>Script Demo</title>
            <style>
                  body{
                        margin:0;
                  }
            </style>
            <script language="JavaScript">
                  function getWinResized(){
                        var dataObj=document.getElementById('childData');
                        var ht=dataObj.offsetHeight+40;
                        var wd=dataObj.offsetWidth+35;
                        window.resizeTo(wd,ht);
                  }
            </script>
      </head>
<body onload="getWinResized()">
      <table cellpadding="0" cellspacing="10" border="0" id="childData">
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
            <tr>
                  <td>col1</td>
                  <td>col2</td>
                  <td>col3</td>
            </tr>
      </table>
</body>
</html>

=================================

Experiment it by adding more rows to the table inside child window.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now