Solved

Open a auto sizeable window

Posted on 2006-11-13
5
197 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

911 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

22 Experts available now in Live!

Get 1:1 Help Now