Suntower
Posts: 225
|
| Posted: 07/22/2008, 2:00 PM |
|
JS Newbie Question...
I have a number of popup windows which are used to select from a list... I basically use the technique in the CCS examples.
Rather than have them 'timeout' as they do now, I would rather that they automatically close if the user doesn't select within a certain period of time.
I -thought- I could do something like...
<script language="JavaScript" type="text/javascript">
function winClose()
{
window.setTimeOut("window.close();",5000)
}
</script>
<body onload="winClose();">
...and so on...
This doesn't work. It appears that the function is totally ignored. Why? Is it because I'm using ASP? Is there some obvious mistake I'm making? I've seen many, many variations in grammar (some with semi-colons, some without for example) but nothing I've tried 'works'.
Help?!!!
Thanks,
---JC
_________________
---On a campaign for more examples and better docs! |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/22/2008, 2:21 PM |
|
One would think that would work for you.
Have you tried other functions in the setTimeout function like alert("something") or window.location='somepage'?
I'd try that just to see if the setTimeout function is working as expected. (Sometimes close window does not behave as one would like.
If window location works, you could link to a dummy page that just does a close window.
Just some thoughts
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
Suntower
Posts: 225
|
| Posted: 07/22/2008, 2:31 PM |
|
---Yes I tried substituting alert as follows:
<script language="JavaScript" type="text/javascript">
function winClose()
{
window.setTimeOut("alert('Hi there');",5000)
}
</script>
---That doesn't fire either. So I was wondering if it was a conflict with ASP or some dumb grammar mistake of mine?
Anyone?
---JC
Quote jjrjr1:
One would think that would work for you.
Have you tried other functions in the setTimeout function like alert("something") or window.location='somepage'?
I'd try that just to see if the setTimeout function is working as expected. (Sometimes close window does not behave as one would like.
If window location works, you could link to a dummy page that just does a close window.
Just some thoughts
_________________
---On a campaign for more examples and better docs! |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/22/2008, 3:16 PM |
|
I doubt it is a conflict with ASP since one happens at the server and one happens at the client side.
I will play with it a little.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
datadoit
|
| Posted: 07/22/2008, 3:56 PM |
|
Try this:
<script language="javascript">
var intValue = 0
function myMethod(){
window.close();
}
</script>
<body onLoad="intValue=window.setTimeout('myMethod()', 5000);">
|
|
|
 |
mentecky
Posts: 321
|
| Posted: 07/22/2008, 4:37 PM |
|
Quote Suntower:
JS Newbie Question...
I have a number of popup windows which are used to select from a list... I basically use the technique in the CCS examples.
Rather than have them 'timeout' as they do now, I would rather that they automatically close if the user doesn't select within a certain period of time.
I -thought- I could do something like...
<script language="JavaScript" type="text/javascript">
function winClose()
{
window.setTimeOut("window.close();",5000)
}
</script>
<body onload="winClose();">
...and so on...
This doesn't work. It appears that the function is totally ignored. Why? Is it because I'm using ASP? Is there some obvious mistake I'm making? I've seen many, many variations in grammar (some with semi-colons, some without for example) but nothing I've tried 'works'.
Help?!!!
Thanks,
---JC
I'll take my turn at this. 
First, in the page CLIENT On Load event put something like:
t = setTimeout("timeout_Page()", 10 * 60 * 1000);
The 10 in that is the number of minutes for the timeout.
Next, Scroll up in the code and look for a white area where we can enter code without CCS regenerating over ours. Usually the first white space above our On Load function is good. Enter:
var t;
function timeout_Page()
{
window.close();
}
I use similar code to logout a user if they haven't changed pages in a while. The reason to use the On Load event in CCS rather than putting our own code in the <body> tag is CCS does BIND EVENTS and may write over our manually created events.
Rick
_________________
http://www.ccselite.com |
 |
 |
Suntower
Posts: 225
|
| Posted: 07/22/2008, 4:41 PM |
|
That seems to work! Without appearing -greedy- I now have some followups...
1. Why does this work and my previous example -not-? Does setTimeout require a 'dummy' return value? Or was there something else I was missing?
2. Can this be transferred to the -caller- link? ie. I was originally trying to get the 'parent' window to control the 'timeout'. Here's the original code for the 'parent' which calls the popupwindow. What I would ideally like to be able to do is
var intValue = 0
function myMethod(){
window.close();
}
function OpenProducts_List()
{
var FieldValue;
var win=window.open("PRODUCTS_list.asp?ORDERTYPE=T", "PRODUCTS_List", "left=100,top=10,width=480,height=480,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
win.focus();
win.setTimeout('myMethod()', 5000);">
}
<a href="{PRODUCTS_list_Src}" id="PRODUCTS_List" style="COLOR: saddlebrown" onclick="OpenProducts_List();return false;">Select A Product</a>
...but I can't get this to work either. Can you help with -this- variation on the theme?
THANKS!!!!!
---JC
Quote datadoit:
Try this:
<script language="javascript">
var intValue = 0
function myMethod(){
window.close();
}
</script>
<body onLoad="intValue=window.setTimeout('myMethod()', 5000);">
_________________
---On a campaign for more examples and better docs! |
 |
 |
Suntower
Posts: 225
|
| Posted: 07/22/2008, 4:51 PM |
|
PS... Another option would be... if I could modify the code to either call the function or NOT depending on a GET or POST parameter. Is that easier to achieve?
Thanks,
---JC
_________________
---On a campaign for more examples and better docs! |
 |
 |
mentecky
Posts: 321
|
| Posted: 07/22/2008, 5:13 PM |
|
Quote Suntower:
PS... Another option would be... if I could modify the code to either call the function or NOT depending on a GET or POST parameter. Is that easier to achieve?
Thanks,
---JC
Which method did you use so I know what code to bend?
Rick
_________________
http://www.ccselite.com |
 |
 |
Suntower
Posts: 225
|
| Posted: 07/22/2008, 5:43 PM |
|
The solution provided by 'Datadoit' worked. However, I need to take it one step further. Frankly, I don't care which I end up with.
I need to be able control whether or not the called 'procedure (the 'called' URL times out after 5 minutes -or- remains open indefinitely. I figure this could be achieved either by
a. Tthe 'caller' (parent) window sending the .close method as in my previous message, -or-
b. By passing a GET or POST parameter to the popup as part of it's URL. Again, I don't care which, I just need to be able to get one or the other method to work.
In a. I don't know the proper syntax to use the .close method... or rather, what I tried did not work.
In b. I don't know how to retrieve a GET or POST parameter in JS.
Ideas?
---JC
Quote mentecky:
Quote Suntower:
PS... Another option would be... if I could modify the code to either call the function or NOT depending on a GET or POST parameter. Is that easier to achieve?
Thanks,
---JC
Which method did you use so I know what code to bend?
Rick
_________________
---On a campaign for more examples and better docs! |
 |
 |
datadoit
|
| Posted: 07/22/2008, 5:49 PM |
|
Here's info on retrieving URL parameters via javascript:
http://www.netlobo.com/url_query_string_javascript.html
|
|
|
 |
datadoit
|
| Posted: 07/22/2008, 5:57 PM |
|
Suntower wrote:
> 1. Why does this work and my previous example -not-? Does setTimeout require a
> 'dummy' return value? Or was there something else I was missing?
>
------------------------
I don't know... think it's something to do with javascript objects
(whatever that means). :)
I also think this may work for you:
<script language="javascript">
var t = window.setTimeout('window.close()', 5000);
</script>
|
|
|
 |
mentecky
Posts: 321
|
| Posted: 07/22/2008, 6:01 PM |
|
Using datadoit's code, which is good, I'd do something like:
<script language="javascript">
var intValue = 0
function myMethod(){
if ({auto_close} == 1)
window.close();
}
</script>
<body onLoad="intValue=window.setTimeout('myMethod()', 5000);">
And in the page server side Before Show put:
global $Tpl;
$Tpl->SetVar("auto_close", CCGetParam("auto_close", "0"));
Then add "auto_close=1" to your open URL. When you want the window to close itself.
Rick
_________________
http://www.ccselite.com |
 |
 |
datadoit
|
| Posted: 07/22/2008, 6:13 PM |
|
Definitely put your function in the child nodes, and use Richard's
suggestion of putting it in CCS's Client On Load event.
You can use the gup() function to test for URL parameters:
<code>
//page_OnLoad @1-D0F4E1D3
function page_OnLoad()
{
var result;
//End page_OnLoad
//Custom Code @2-2A29BDB7
// -------------------------
// Write your own code here.
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
var CloseIt = gup( 'close' );
if ( CloseIt == 'true' )
var t = window.setTimeout('window.close()', 5000);
// -------------------------
//End Custom Code
//Close page_OnLoad @1-BC33A33A
return result;
}
//End Close page_OnLoad
</code>
So when you call it, add the parameter 'close' to your URL:
var win=window.open("PRODUCTS_list.asp?ORDERTYPE=T&close=true" ...
|
|
|
 |
Suntower
Posts: 225
|
| Posted: 07/23/2008, 11:55 AM |
|
Did I mention that you guys just totally RAWWWWWK?! :D
Thanks,
PS... I dunno what happened but I gotta add whilst in the flush of happiness... the response time is AMAZING. The first few years I owned CCS I'd post questions and it would not be uncommon to not get any replies for -days- if ever. I was so frustrated with the lack of responsiveness (not to mention the docs) that I almost gave up. But the past few questions I've had have been answered promptly and thoroughly and I am almost orgasmic... OK, not quite.
Whatever has happened, I just want to say THANKS to all. I hope someday to know enough to be able to reciprocate as needed. BIG CHEERS!
_________________
---On a campaign for more examples and better docs! |
 |
 |
mentecky
Posts: 321
|
| Posted: 07/23/2008, 12:49 PM |
|
Suntower,
No problem. Glad we could help!
Point goes to datadoit for initial goal... I'll take an assist 
Rick
_________________
http://www.ccselite.com |
 |
 |
wkempees
Posts: 1679
|
| Posted: 07/24/2008, 6:09 AM |
|
Fast answers are invoked by interesting questions!
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
Suntower
Posts: 225
|
| Posted: 07/24/2008, 1:33 PM |
|
Hi Walter,
I'll try to make all future questions as gripping and compelling as possible. Maybe if I throw in some gratuitous s e x and violence.
---JC
Quote wkempees:
Fast answers are invoked by interesting questions!
PS To Mods: Apparently the word 'sex' alone... even as a joke is verboten? Kind of a humourless policy, don't you think?
_________________
---On a campaign for more examples and better docs! |
 |
 |
|