/    Sign up×
Community /Pin to ProfileBookmark

Trying to Use a Window Repeatedly but Reconfigured

Hello. I would like to be able to change the height of a child window depending on the size of what gets loaded to it, and re-use the same window again and again, changing its height each time as appropriate.

So far, I find that if I try the following:

function MyWin(url,h){
features=’screenX=320,screenY=60,left=320,top=30,resizable,height=’ + h + ‘,width=600,scrollbars’;
win=window.open(url,features,true);
win.focus();
}

Then whatever height the window opens with the first time is the height it opens with on subsequent function calls no matter what new height parm is passed.

If I try the following:

function MyWin(nm,url,h){
features=’screenX=320,screenY=60,left=320,top=30,resizable,height=’ + h + ‘,width=600,scrollbars’;
win=window.open(url,nm,features,true);
win.focus();
}

This solves the above problem (each new height parm value is now responded to correctly), but it creates a different problem: instead of re-using the same window again and again as I had intended, a separate window opens for each different name (nm) parm. This is not at all what I want since it simply clutters up the user’s desktop (or task bar), and requires him to perform the needless extra step of closing each window himself.

It does not seem to help to add if (!win.closed) win.close() at the top of the function. And the fourth ‘true’ value (for the parameter named ‘replace’) seems to make no difference either (not that I understand exactly what ‘replace’ means here).

Any ideas?

Thanks for your help!

Peyton

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@kennyvAug 28.2009 — Looks like the variable nm needs to be the same all the time.

If you give nm a different value then you have a different window.

Ken

www.webdesigntips-foreveryone.com
Copy linkTweet thisAlerts:
@peytontoddauthorAug 29.2009 — The solution you suggest is actually the first one I had tried. My apologies for the mistake I made in describing my first version: The window.open command actually REQUIRES a name parameter, thus: window.open(url,name,features). And that is what I used on my first attempt - always the same name. Then when my second solution failed and I wrote the post describing my problem, I erroneously chopped out the name parameter instead of using the same one on all function calls. Sorry.

So I'm still stuck as to what to do...
Copy linkTweet thisAlerts:
@kennyvAug 29.2009 — I copied your first example and modified it slightly as follows:

function MyWin(url,h){

features='screenX=320,screenY=60,left=320,top=30,resizable,height=' + h + ',width=600,scrollbars';

alert(features)

win=window.open(url,"win",features,true);

win.focus();

}

This works, however if the window "win" is not closed before the next one is open then the size is the same. If the user closes the sized window and clicks a different link with a different height it will open with the proper height.

Ken

www.webdesigntips-foreveryone.com
Copy linkTweet thisAlerts:
@peytontoddauthorAug 31.2009 — The point was so the user would not have to close the window himself. Rather, if it's open already when the user clicks a second choice of contents for it (i.e., to fill it with either more or less material than it contained when initially opened), it should close automatically before reopening. In my lack of understanding of the matter, I tried both the following as the first line of the function, to no avail:

if (!win.closed) win.close();

if (typeof win != undefined) win.close();

Most likely there's a way to do this, I just don't know what it is. Thanks for your efforts so far, and if you (or anyone else reading this?) knows what it might be, it would be a great help!

Peyton ?
Copy linkTweet thisAlerts:
@kennyvAug 31.2009 — Peyton,

Try changing the function to this:

features='screenX=320,screenY=60,left=320,top=30,resizable,height=' + h + ',width=600,scrollbars';

win=window.open(url,"win",features,true);

win.resizeTo(600,h)

win.focus();

I tested it and it should do what you want.

Ken

www.webdesigntips-foreveryone.com
Copy linkTweet thisAlerts:
@peytontoddauthorSep 01.2009 — Before I forget, let me express my gratitude to you for solving the problem. Now that I see the solution, I recall that solution was what I was driven to myself back when I used to program regularly for the web going on 7 years ago now. But these many years later, without your help I was ready to give up.

So thanks!

Peyton ?
×

Success!

Help @peytontodd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...