SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot Oznob's Avatar
    Join Date
    Jun 2002
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    script help - popups

    I have a page with a number of popup links (about 20 or more).

    Here is the javascript code:

    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
    }
    </script>


    Here is the link code:


    <a href="javascript:MM_openBrWindow('page.htm','popup1',' width=766,height=700')">Link</a>


    Here is another link on the page:

    <a href="javascript:MM_openBrWindow('page2.htm','popup1',' width=766,height=700')">Link</a>


    I have about 20 links like this on the one page.

    PROBLEM: I kept the popup name of each page 'popup1' because I only want to have 1 popup at a time on the user's screen. The problem is that when I click a different link, the content changes correctly - but the attributes of the popup window do not (i.e. the width and height are not updated to make the 'popup1' window change size).

    QUESTION: Is there something simple I can add to either the javascript up in my header or in the link itself that will FIRST close down the 'popup1' window - and THEN open the new 'popup1' window with the new attributes ? (I think this should fix the problem of it not changing size).

    Thanks in advance - I posted this problem a week or so ago - but never got a solution - hope I am more clear this time.

    Oznob

  2. #2
    SitePoint Addict NikoB's Avatar
    Join Date
    Nov 2005
    Location
    Austria
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually there are two ways to accomplish that:
    You could hold the popup in a variable lke:
    Code:
    var wnd = null
    <!--
    function MM_openBrWindow(theURL,winName,features) { //v2.0
    if (wnd != null) wnd.close();
    wnd = window.open(theURL,winName,features);
    }
    or you resize the window using the htm itself... in page.htm you could do
    Code:
    	if (!document.all) {
    		window.sizeToContent();
    		window.sizeToContent();	// for reasons beyond understanding,
    					// only if we call it twice we get the
    					// correct size.
    		// center on parent
    		var x = (screen.width - window.outerWidth) / 2;
    		var y = (screen.height - window.outerHeight) / 2;
    		window.moveTo(x, y);
    		window.resizeTo(540, 300);
    	} else {
    		// window.dialogHeight = body.offsetHeight + 50 + "px";
    		// window.dialogWidth = body.offsetWidth + "px";
    		window.resizeTo(540, 400);
    		var ch = body.clientHeight;
    		var cw = body.clientWidth;
    		var W = body.offsetWidth;
    		var H = 2 * body_height - ch;
    		var x = (screen.availWidth - W) / 2;
    		var y = (screen.availHeight - H) / 2;
    		window.moveTo(x, y);
    	}
    Corinis OpenSource Community & Content Management
    http://www.corinis.org

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    That document.all reference will cause the code to stuff up in Opera. Test for window.sizeToContent instead.

    if (window.sizeToContent)

    instead of

    if (document.all)
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Addict NikoB's Avatar
    Join Date
    Nov 2005
    Location
    Austria
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    true... sizetocontent is better...
    Corinis OpenSource Community & Content Management
    http://www.corinis.org


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •