remcogoris
asked on
Javascript variable declaration
Hi!
I am not an expert at all in javascript, so this is a simple question (i hope)
How do I create/declare variables in javascript?
In the code below, I get a Javascript error on the first line in function Minimize()
The error says that window.document.frmCloseSe tting.itfl ag.value is null or is not an object.
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var windowX=100;
var windowY=100;
var windowWidth=400;
var windowHeight=300;
var autocenter = true;
var autoclose = false;
var beIE=document.all?true:fal se;
function setMesg(){
mess = "Warning: Only click OK if you are terminating your forms application. Clicking OK while Forms application is up and running will result in the loss of your session!"
if (window.document.frmCloseS etting.itf lag.value= =0)
return mess;
else
return;
}
function Minimizee() {
window.moveTo(10000,10000) ;
window.blur();
window.onfocus = new Function("window.moveTo(10 000,10000) ;");
}
function MinimizeIt() {
window.document.frmCloseSe tting.itfl ag.value=1 ;
Minimizee();
window.document.frmCloseSe tting.itfl ag.value=0 ;
}
function CloseIt() {
window.document.frmCloseSe tting.itfl ag.value=0 ;
window.close();
}
-->
</SCRIPT>
Thanks!
Remco
I am not an expert at all in javascript, so this is a simple question (i hope)
How do I create/declare variables in javascript?
In the code below, I get a Javascript error on the first line in function Minimize()
The error says that window.document.frmCloseSe
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var windowX=100;
var windowY=100;
var windowWidth=400;
var windowHeight=300;
var autocenter = true;
var autoclose = false;
var beIE=document.all?true:fal
function setMesg(){
mess = "Warning: Only click OK if you are terminating your forms application. Clicking OK while Forms application is up and running will result in the loss of your session!"
if (window.document.frmCloseS
return mess;
else
return;
}
function Minimizee() {
window.moveTo(10000,10000)
window.blur();
window.onfocus = new Function("window.moveTo(10
}
function MinimizeIt() {
window.document.frmCloseSe
Minimizee();
window.document.frmCloseSe
}
function CloseIt() {
window.document.frmCloseSe
window.close();
}
-->
</SCRIPT>
Thanks!
Remco
Hi,
Sorry, after looking carefully, the script consistently calls Minimizee().
As for declaring variables, it's as simple as saying
var myVariableName
just like in your code e.g.
var windowX=100
As for the error, it's because the script cannot find the object with name itflag in your HTML form. Make sure you have such a object in your HTML form. Sth like
<input name="itflag" type="hidden" id="itflag" value="1">
Cheers
Nickson
Sorry, after looking carefully, the script consistently calls Minimizee().
As for declaring variables, it's as simple as saying
var myVariableName
just like in your code e.g.
var windowX=100
As for the error, it's because the script cannot find the object with name itflag in your HTML form. Make sure you have such a object in your HTML form. Sth like
<input name="itflag" type="hidden" id="itflag" value="1">
Cheers
Nickson
It looks like you are trying a lot of stuff at times where the browser may or may not respond or allow you.
You cannot rely on a form field being present in a page in a function your call onUnload for example
Michel
You cannot rely on a form field being present in a page in a function your call onUnload for example
Michel
Do it like this:
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var winMin = false;
function MinimizeIt() {
winMin = true;
Minimizee();
winMin = false;
}
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var winMin = false;
function MinimizeIt() {
winMin = true;
Minimizee();
winMin = false;
}
ASKER
Hm. Thanks for your reactions.
I have tried
<input name="itflag" type="hidden" id="itflag" value="1">
But the same error occurs. Has to do with the place of the code relative to the javascript code?
As for Zvonko's suggestion: I haven't tried it yet, because I think the problem is, that the variable value isn't persistent. I will add the full html code, hoping this will clarify its use. An Oracle Forms applet is started by this page - the applet is opened in a separate window. I am trying to arrive at a situation where an end-user is able to 'minimize' the hosting browser-window to a position where it cannot be seen, AND where the end-user is warned when closing the browser-window, that she will also close the actual application (applet).
<HTML>
<!-- FILE: webutiljini.htm (Oracle Forms) -->
<!-- -->
<!-- This is the a HTML template file for running a form on the -->
<!-- web using JInitiator-style tags to include the Forms applet. -->
<!-- and a certificate regsitration applet for the WebUtil utility -->
<!-- -->
<!-- IMPORTANT NOTES: -->
<!-- Default values for all the variables which appear below -->
<!-- (enclosed in percent characters) are defined in the servlet -->
<!-- configuration file (formsweb.cfg). It is preferable to make -->
<!-- changes in that file where possible, rather than this one. -->
<!-- -->
<!-- This file uses several extra tags that are not present in the -->
<!-- default template files. You should ensure that these are -->
<!-- present in the configuration that uses this template -->
<!-- The extra substitution Tags are: -->
<!-- %webUtilArchive% = jar file containing the WebUtil code -->
<!-- (by default this should be frmwebutil.jar) -->
<!-- %WebUtilLogging% = Defines the current logging mode. -->
<!-- Valid values: off|on|console|server|all -->
<!-- (on == console) -->
<!-- %WebUtilLoggingDetail% = Specifies the level of error logging.-->
<!-- Valid values: normal|detailed -->
<!-- %WebUtilErrorMode% = Should errors be displayed in an alert -->
<!-- as well as the programmer defined -->
<!-- locations -->
<!-- Valid values: console|server|alert|all -->
<!-- %WebUtilDispatchMonitorInt erval% = Counts in second to -->
<!-- indicate how often the monitor thread -->
<!-- checks to see if the Forms session is still-->
<!-- alive. Used with the WebUtil_Session -->
<!-- package. -->
<!-- %WebUtilTrustInternal% = Should intranet without domain suffix-->
<!-- be trusted. -->
<!-- Valid values: true|yes|false|no -->
<!-- %WebUtilMaxTransferSize% = Size in bytes of file transfer -->
<!-- segments. Default and maximum allowed is -->
<!-- 16384, i.e. 16K. -->
<HEAD><TITLE>%pageTitle% - WebUtil</TITLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var windowX=100;
var windowY=100;
var windowWidth=400;
var windowHeight=300;
var autocenter = true;
var autoclose = false;
var beIE=document.all?true:fal se;
function setMesg(){
mess = "Warning: Only click OK if you are terminating your forms application. Clicking OK while Forms application is up and running will result in the loss of your session!"
if (window.document.frmCloseS etting.itf lag.value= =0)
return mess;
else
return;
}
function Minimizee() {
window.moveTo(10000,10000) ;
window.blur();
window.onfocus = new Function("window.moveTo(10 000,10000) ;");
}
function MinimizeIt() {
window.document.frmCloseSe tting.itfl ag.value=1 ;
Minimizee();
window.document.frmCloseSe tting.itfl ag.value=0 ;
}
function CloseIt() {
window.document.itflag.val ue=0
window.document.frmCloseSe tting.itfl ag.value=0 ;
window.close();
}
-->
</SCRIPT>
<noscript> JavaScript is not enabled in your Browser. </noscript>
</HEAD>
<BODY %HTMLbodyAttrs% scroll="no" onbeforeunload="return setMesg()">
%HTMLbeforeForm%
<input name="itflag" type="hidden" id="itflag" value="1">
<a href="javascript:MinimizeI t()">Minim ize</a>
<!-- Registration applet definition (start) -->
<OBJECT classid="%jinit_classid%"
codebase="/forms/jinitiato r/%jinit_e xename%"
WIDTH="0"
HEIGHT="0"
HSPACE="0"
VSPACE="0">
<PARAM NAME="TYPE" VALUE="%jinit_mimetype%">
<PARAM NAME="CODEBASE" VALUE="%codebase%">
<PARAM NAME="CODE" VALUE="oracle.forms.webuti l.common.R egisterWeb Util" >
<PARAM NAME="ARCHIVE" VALUE="%webUtilArchive%" >
<COMMENT>
<EMBED SRC="" PLUGINSPAGE="%jinit_downlo ad_page%"
TYPE="%jinit_mimetype%"
java_codebase="%codebase%"
java_code="oracle.forms.we butil.comm on.Registe rWebUtil"
java_archive="%webUtilArch ive%"
WIDTH="1"
HEIGHT="1"
HSPACE="0"
VSPACE="0"
>
<NOEMBED>
</COMMENT>
</NOEMBED></EMBED>
</OBJECT>
<!-- Registration applet definition (end) -->
<!-- Forms applet definition (start) -->
<OBJECT classid="%jinit_classid%"
codebase="/forms/jinitiato r/%jinit_e xename%"
WIDTH="%Width%"
HEIGHT="%Height%"
HSPACE="0"
VSPACE="0">
<PARAM NAME="TYPE" VALUE="%jinit_mimetype%">
<PARAM NAME="CODEBASE" VALUE="%codebase%">
<PARAM NAME="CODE" VALUE="oracle.forms.engine .Main" >
<PARAM NAME="ARCHIVE" VALUE="%archive_jini%,%web UtilArchiv e%" >
<PARAM NAME="serverURL" VALUE="%serverURL%">
<PARAM NAME="networkRetries" VALUE="%networkRetries%">
<PARAM NAME="serverArgs"
VALUE="%escapeParams% module=%form% userid=%userid% sso_userid=%sso_userid% sso_formsid=%sso_formsid% sso_subDN=%sso_subDN% sso_usrDN=%sso_usrDN% debug=%debug% host=%host% port=%port% %otherParams%">
<PARAM NAME="separateFrame" VALUE="%separateFrame%">
<PARAM NAME="splashScreen" VALUE="%splashScreen%">
<PARAM NAME="background" VALUE="%background%">
<PARAM NAME="lookAndFeel" VALUE="%lookAndFeel%">
<PARAM NAME="colorScheme" VALUE="%colorScheme%">
<PARAM NAME="serverApp" VALUE="%serverApp%">
<PARAM NAME="logo" VALUE="%logo%">
<PARAM NAME="imageBase" VALUE="%imageBase%">
<PARAM NAME="formsMessageListener " VALUE="%formsMessageListen er%">
<PARAM NAME="recordFileName" VALUE="%recordFileName%">
<PARAM NAME="EndUserMonitoringEna bled" VALUE="%EndUserMonitoringE nabled%">
<PARAM NAME="EndUserMonitoringURL " VALUE="%EndUserMonitoringU RL%">
<PARAM NAME="heartbeat" VALUE="%heartbeat%">
<PARAM NAME="WebUtilLogging" VALUE="%WebUtilLogging%">
<PARAM NAME="WebUtilLoggingDetail " VALUE="%WebUtilLoggingDeta il%">
<PARAM NAME="WebUtilErrorMode" VALUE="%WebUtilErrorMode%" >
<PARAM NAME="WebUtilDispatchMonit orInterval " VALUE="%WebUtilDispatchMon itorInterv al%">
<PARAM NAME="WebUtilTrustInternal " VALUE="%WebUtilTrustIntern al%">
<PARAM NAME="WebUtilMaxTransferSi ze" VALUE="%WebUtilMaxTransfer Size%">
<COMMENT>
<EMBED SRC="" PLUGINSPAGE="%jinit_downlo ad_page%"
TYPE="%jinit_mimetype%"
java_codebase="%codebase%"
java_code="oracle.forms.en gine.Main"
java_archive="%archive_jin i%,%webUti lArchive%"
WIDTH="%Width%"
HEIGHT="%Height%"
HSPACE="0"
VSPACE="0"
serverURL="%serverURL%"
networkRetries="%networkRe tries%"
serverArgs="%escapeParams% module=%form% userid=%userid% sso_userid=%sso_userid% sso_formsid=%sso_formsid% sso_subDN=%sso_subDN% sso_usrDN=%sso_usrDN% debug=%debug% host=%host% port=%port% %otherparams%"
separateFrame="%separateFr ame%"
splashScreen="%splashScree n%"
background="%background%"
lookAndFeel="%lookAndFeel% "
colorScheme="%colorScheme% "
serverApp="%serverApp%"
logo="%logo%"
imageBase="%imageBase%"
formsMessageListener="%for msMessageL istener%"
recordFileName="%recordFil eName%"
EndUserMonitoringEnabled=" %EndUserMo nitoringEn abled%"
EndUserMonitoringURL="%End UserMonito ringURL%"
heartBeat="%heartBeat%"
WebUtilLogging="%WebUtilLo gging%"
WebUtilLoggingDetail="%Web UtilLoggin gDetail%"
WebUtilErrormode="%WebUtil ErrorMode% "
WebUtilDispatchMonitorInte rval="%Web UtilDispat chMonitorI nterval%"
WebUtilTrustInternal="%Web UtilTrustI nternal%"
WebUtilMaxTransferSize="%W ebUtilMaxT ransferSiz e%"
>
<NOEMBED>
</COMMENT>
</NOEMBED></EMBED>
</OBJECT>
<!-- Forms applet definition (end) -->
<!--
<a href="javascript:CloseIt() ">close</a >
-->
%HTMLafterForm%
</BODY>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
//Control should not come here after loading the html page.
if (autocenter)
{
windowX = ( window.screen.width-window Width ) / 2;
windowY = (window.screen.height-wind owHeight)/ 2;
window.resizeTo(windowWidt h,windowHe ight);
window.moveTo(windowX,wind owY);
window.resizeTo(300,300);
}
-->
</SCRIPT>
</HTML>
I have tried
<input name="itflag" type="hidden" id="itflag" value="1">
But the same error occurs. Has to do with the place of the code relative to the javascript code?
As for Zvonko's suggestion: I haven't tried it yet, because I think the problem is, that the variable value isn't persistent. I will add the full html code, hoping this will clarify its use. An Oracle Forms applet is started by this page - the applet is opened in a separate window. I am trying to arrive at a situation where an end-user is able to 'minimize' the hosting browser-window to a position where it cannot be seen, AND where the end-user is warned when closing the browser-window, that she will also close the actual application (applet).
<HTML>
<!-- FILE: webutiljini.htm (Oracle Forms) -->
<!-- -->
<!-- This is the a HTML template file for running a form on the -->
<!-- web using JInitiator-style tags to include the Forms applet. -->
<!-- and a certificate regsitration applet for the WebUtil utility -->
<!-- -->
<!-- IMPORTANT NOTES: -->
<!-- Default values for all the variables which appear below -->
<!-- (enclosed in percent characters) are defined in the servlet -->
<!-- configuration file (formsweb.cfg). It is preferable to make -->
<!-- changes in that file where possible, rather than this one. -->
<!-- -->
<!-- This file uses several extra tags that are not present in the -->
<!-- default template files. You should ensure that these are -->
<!-- present in the configuration that uses this template -->
<!-- The extra substitution Tags are: -->
<!-- %webUtilArchive% = jar file containing the WebUtil code -->
<!-- (by default this should be frmwebutil.jar) -->
<!-- %WebUtilLogging% = Defines the current logging mode. -->
<!-- Valid values: off|on|console|server|all -->
<!-- (on == console) -->
<!-- %WebUtilLoggingDetail% = Specifies the level of error logging.-->
<!-- Valid values: normal|detailed -->
<!-- %WebUtilErrorMode% = Should errors be displayed in an alert -->
<!-- as well as the programmer defined -->
<!-- locations -->
<!-- Valid values: console|server|alert|all -->
<!-- %WebUtilDispatchMonitorInt
<!-- indicate how often the monitor thread -->
<!-- checks to see if the Forms session is still-->
<!-- alive. Used with the WebUtil_Session -->
<!-- package. -->
<!-- %WebUtilTrustInternal% = Should intranet without domain suffix-->
<!-- be trusted. -->
<!-- Valid values: true|yes|false|no -->
<!-- %WebUtilMaxTransferSize% = Size in bytes of file transfer -->
<!-- segments. Default and maximum allowed is -->
<!-- 16384, i.e. 16K. -->
<HEAD><TITLE>%pageTitle% - WebUtil</TITLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var windowX=100;
var windowY=100;
var windowWidth=400;
var windowHeight=300;
var autocenter = true;
var autoclose = false;
var beIE=document.all?true:fal
function setMesg(){
mess = "Warning: Only click OK if you are terminating your forms application. Clicking OK while Forms application is up and running will result in the loss of your session!"
if (window.document.frmCloseS
return mess;
else
return;
}
function Minimizee() {
window.moveTo(10000,10000)
window.blur();
window.onfocus = new Function("window.moveTo(10
}
function MinimizeIt() {
window.document.frmCloseSe
Minimizee();
window.document.frmCloseSe
}
function CloseIt() {
window.document.itflag.val
window.document.frmCloseSe
window.close();
}
-->
</SCRIPT>
<noscript> JavaScript is not enabled in your Browser. </noscript>
</HEAD>
<BODY %HTMLbodyAttrs% scroll="no" onbeforeunload="return setMesg()">
%HTMLbeforeForm%
<input name="itflag" type="hidden" id="itflag" value="1">
<a href="javascript:MinimizeI
<!-- Registration applet definition (start) -->
<OBJECT classid="%jinit_classid%"
codebase="/forms/jinitiato
WIDTH="0"
HEIGHT="0"
HSPACE="0"
VSPACE="0">
<PARAM NAME="TYPE" VALUE="%jinit_mimetype%">
<PARAM NAME="CODEBASE" VALUE="%codebase%">
<PARAM NAME="CODE" VALUE="oracle.forms.webuti
<PARAM NAME="ARCHIVE" VALUE="%webUtilArchive%" >
<COMMENT>
<EMBED SRC="" PLUGINSPAGE="%jinit_downlo
TYPE="%jinit_mimetype%"
java_codebase="%codebase%"
java_code="oracle.forms.we
java_archive="%webUtilArch
WIDTH="1"
HEIGHT="1"
HSPACE="0"
VSPACE="0"
>
<NOEMBED>
</COMMENT>
</NOEMBED></EMBED>
</OBJECT>
<!-- Registration applet definition (end) -->
<!-- Forms applet definition (start) -->
<OBJECT classid="%jinit_classid%"
codebase="/forms/jinitiato
WIDTH="%Width%"
HEIGHT="%Height%"
HSPACE="0"
VSPACE="0">
<PARAM NAME="TYPE" VALUE="%jinit_mimetype%">
<PARAM NAME="CODEBASE" VALUE="%codebase%">
<PARAM NAME="CODE" VALUE="oracle.forms.engine
<PARAM NAME="ARCHIVE" VALUE="%archive_jini%,%web
<PARAM NAME="serverURL" VALUE="%serverURL%">
<PARAM NAME="networkRetries" VALUE="%networkRetries%">
<PARAM NAME="serverArgs"
VALUE="%escapeParams% module=%form% userid=%userid% sso_userid=%sso_userid% sso_formsid=%sso_formsid% sso_subDN=%sso_subDN% sso_usrDN=%sso_usrDN% debug=%debug% host=%host% port=%port% %otherParams%">
<PARAM NAME="separateFrame" VALUE="%separateFrame%">
<PARAM NAME="splashScreen" VALUE="%splashScreen%">
<PARAM NAME="background" VALUE="%background%">
<PARAM NAME="lookAndFeel" VALUE="%lookAndFeel%">
<PARAM NAME="colorScheme" VALUE="%colorScheme%">
<PARAM NAME="serverApp" VALUE="%serverApp%">
<PARAM NAME="logo" VALUE="%logo%">
<PARAM NAME="imageBase" VALUE="%imageBase%">
<PARAM NAME="formsMessageListener
<PARAM NAME="recordFileName" VALUE="%recordFileName%">
<PARAM NAME="EndUserMonitoringEna
<PARAM NAME="EndUserMonitoringURL
<PARAM NAME="heartbeat" VALUE="%heartbeat%">
<PARAM NAME="WebUtilLogging" VALUE="%WebUtilLogging%">
<PARAM NAME="WebUtilLoggingDetail
<PARAM NAME="WebUtilErrorMode" VALUE="%WebUtilErrorMode%"
<PARAM NAME="WebUtilDispatchMonit
<PARAM NAME="WebUtilTrustInternal
<PARAM NAME="WebUtilMaxTransferSi
<COMMENT>
<EMBED SRC="" PLUGINSPAGE="%jinit_downlo
TYPE="%jinit_mimetype%"
java_codebase="%codebase%"
java_code="oracle.forms.en
java_archive="%archive_jin
WIDTH="%Width%"
HEIGHT="%Height%"
HSPACE="0"
VSPACE="0"
serverURL="%serverURL%"
networkRetries="%networkRe
serverArgs="%escapeParams%
separateFrame="%separateFr
splashScreen="%splashScree
background="%background%"
lookAndFeel="%lookAndFeel%
colorScheme="%colorScheme%
serverApp="%serverApp%"
logo="%logo%"
imageBase="%imageBase%"
formsMessageListener="%for
recordFileName="%recordFil
EndUserMonitoringEnabled="
EndUserMonitoringURL="%End
heartBeat="%heartBeat%"
WebUtilLogging="%WebUtilLo
WebUtilLoggingDetail="%Web
WebUtilErrormode="%WebUtil
WebUtilDispatchMonitorInte
WebUtilTrustInternal="%Web
WebUtilMaxTransferSize="%W
>
<NOEMBED>
</COMMENT>
</NOEMBED></EMBED>
</OBJECT>
<!-- Forms applet definition (end) -->
<!--
<a href="javascript:CloseIt()
-->
%HTMLafterForm%
</BODY>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
//Control should not come here after loading the html page.
if (autocenter)
{
windowX = ( window.screen.width-window
windowY = (window.screen.height-wind
window.resizeTo(windowWidt
window.moveTo(windowX,wind
window.resizeTo(300,300);
}
-->
</SCRIPT>
</HTML>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Spelling error in function
function Minimizee() {
should be
function Minimize() {
Cheers
Nickson