/    Sign up×
Community /Pin to ProfileBookmark

Using a variable instead of a concrete value!

Hello Everyone,

I am currently developing a small script that will open a “Help Dialog”. The “Help Dialog” is created using the handy ‘window.open()’ function.

Simply opening a window which has been provided with concrete attribute values is easy, e.g.: window.open(‘helpdialog.htm’,’Help’,’height=200, width=200′);

However I am interested in setting the height, width, screenX and screenY information dynamically based upon the users screen resolution (and ultimately the available screen area).

I have written (and included below) code to this end. My challenge lies in setting attribute values dynamically within the code.

e.g.:

var boxHeight = getScreenHeight() / 2;

window.open(‘helpdialog.htm’,’Help’,’height=boxHeight’….)

Simply including the “boxHeight” variable in the window.open() method does not work. I have considered adding height, width, screenX and screenY values to the function call (listed below) which is responsible for opening the new window. However I do not think that this approach will be a fundamental improvement.

Any help with working out how to include dynamic values in my script will be greatly appreciated.

<html>
<head>
<title> Help Pop-Up box spawning page </title>

<script type=”text/javascript”>
//<!–

/***** Determine the available screen area for content display. *****/

var screenHeight = getScreenHeight();
var screenWidth = getScreenWidth();

var boxHeight = screenHeight / 2;
var boxWidth = screenWidth / 2;

function getScreenHeight()
{
if(window.innerHeight) // For NN4 & W3C
{
return window.innerHeight;
}
else
if(document.documentElement) // For IE6+
{
return document.documentElement.offsetHeight;
}
else
if(document.body.clientHeight) // For IE4 & IE5
{
return document.body.clientHeight;
}
}

function getScreenWidth()
{
if(window.innerWidth) // For NN4 & W3C
{
return window.innerWidth;
}
else
if(document.documentElement) // For IE6+
{
return document.documentElement.offsetWidth;
}
else
if(document.body.clientWidth) // For IE4 & IE5
{
return document.body.clientWidth;
}
}

function openWindow(pageAddress, pageName)
{
window.open(pageAddress, pageName, ‘height=boxHeight,width=boxWidth,left=10,top=10,screenX=10,screenY=10’);
}
//–>
</script>
</head>
<body>
<a href=”#” onclick=”openWindow(‘helpbox.htm’,’help’)”>Click for Help Dialog</a>
</body>
</html>

Thanks for your help.

Regards

Davo

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 05.2005 — window.open(pageAddress, pageName, 'height='+boxHeight+',width='+boxWidth+',left=10,top=10,sc reenX=10,screenY=10')
Copy linkTweet thisAlerts:
@CharlesApr 05.2005 — <a href="#" onclick="openWindow('helpbox.htm','help')">Click for Help Dialog</a>[/QUOTE]Bad, very bad. And not at all helpful. Your link willl be broken for the one in ten users who do not use JavaScript and for the countless masses who do use pop-up blockers. If you must open a pop-up do it thusly:

&lt;a href="helpbox.htm" onclick="openWindow(this.href, 'help'); return false"&gt;Click for Help Dialog&lt;/a&gt;
Copy linkTweet thisAlerts:
@WebskaterApr 05.2005 — One for Charles

is 'openWindow(this.href, 'help');' a javascript function? - or is it built-in like onclick?

If it is built-in - are there any attributes to make sure the window opens full screen?
Copy linkTweet thisAlerts:
@CharlesApr 05.2005 — I was referencing Mr. Head's script above. MSIE supports adding "fullscreen", I think it is, to the geometry specification of the Window.prototype.open method. You could play around with getting the screen size but that will only cause problems with some Opera users.
Copy linkTweet thisAlerts:
@WebskaterApr 05.2005 — Thanks for your answer.

Would I be right in thinking that if a user had javascript disabled - they would simply replace the current page with helpbox.htm - if they had javascript enabled - it would call the function?
Copy linkTweet thisAlerts:
@KorApr 05.2005 — yeap. [b]return false[/b] statement will prevent the default HTML action, if javascript is enabled.
×

Success!

Help @Mr_Cube_Head 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...