473,383 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Why is this not working?

opens a new window window_1 which contains a form, uses window
reference to change values there and submits, anyone can have a quick
glimse over this
windows opens ok, nothing happens afterwards : (

var window_1; // global value

function function_1() {
window_1 = window.open('http//...');
setTimeout(function_2, 10000); // 10 secs to load
}

function function_2()
{
window_1.forms['postform'].elements['commenttext'].value = 'test';
window_1.forms['postform'].submit();
}

function_1 is called in body onload in the opened window

Apr 6 '07 #1
12 1701
On Apr 6, 2:37 pm, "Mikhail Kovalev" <mikhail_kova...@mail.ruwrote:
opens a new window window_1 which contains a form, uses window
reference to change values there and submits, anyone can have a quick
glimse over this
windows opens ok, nothing happens afterwards : (

var window_1; // global value

function function_1() {
window_1 = window.open('http//...');
setTimeout(function_2, 10000); // 10 secs to load

}

function function_2()
{
window_1.forms['postform'].elements['commenttext'].value = 'test';
window_1.forms['postform'].submit();

}

function_1 is called in body onload in the opened window

i think when you're doing setTimeout() you have to put the code in
quotes, so it should be:
setTimeout("function_2()", 10000);

and in function_2 i think you want to do winow_1.document.forms rather
than window_1.forms

Apr 6 '07 #2
br************@gmail.com said the following on 4/6/2007 2:59 PM:
On Apr 6, 2:37 pm, "Mikhail Kovalev" <mikhail_kova...@mail.ruwrote:
>opens a new window window_1 which contains a form, uses window
reference to change values there and submits, anyone can have a quick
glimse over this
windows opens ok, nothing happens afterwards : (

var window_1; // global value

function function_1() {
window_1 = window.open('http//...');
setTimeout(function_2, 10000); // 10 secs to load

}

function function_2()
{
window_1.forms['postform'].elements['commenttext'].value = 'test';
window_1.forms['postform'].submit();

}

function_1 is called in body onload in the opened window


i think when you're doing setTimeout() you have to put the code in
quotes, so it should be:
setTimeout("function_2()", 10000);
It is very easy to test whether it should be quoted or not. Try this
code in the browser of your choice:
window.onload=testIt;
function testIt(){
window.setTimeout(myFunction,1000)
window.setTimeout('myFunction2()',2000)
}
function myFunction(){
alert('no quotes used')
}
function myFunction2(){
alert('quotes used')
}
and in function_2 i think you want to do winow_1.document.forms rather
than window_1.forms
Possibly, but window_1.document.forms might work better than winow_1..

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 6 '07 #3
Thanks guys, anyway I figured it out , the script doesnt work bc of
cross site scripting restrictons
The new window Im opening is on another domain

However it tried a similar method with same site in two-split frame
window, and it works in Safari 1.3.2

http://pastebin.se/12827

Could be a security flaw in safari
On 7 Apr, 00:55, Randy Webb <HikksNotAtH...@aol.comwrote:
brunascle.m...@gmail.com said the following on 4/6/2007 2:59 PM:
On Apr 6, 2:37 pm, "Mikhail Kovalev" <mikhail_kova...@mail.ruwrote:
opens a new window window_1 which contains a form, uses window
reference to change values there and submits, anyone can have a quick
glimse over this
windows opens ok, nothing happens afterwards : (
var window_1; // global value
function function_1() {
window_1 = window.open('http//...');
setTimeout(function_2, 10000); // 10 secs to load
}
function function_2()
{
window_1.forms['postform'].elements['commenttext'].value = 'test';
window_1.forms['postform'].submit();
}
function_1 is called in body onload in the opened window
i think when you're doing setTimeout() you have to put the code in
quotes, so it should be:
setTimeout("function_2()", 10000);

It is very easy to test whether it should be quoted or not. Try this
code in the browser of your choice:

window.onload=testIt;
function testIt(){
window.setTimeout(myFunction,1000)
window.setTimeout('myFunction2()',2000)}

function myFunction(){
alert('no quotes used')}

function myFunction2(){
alert('quotes used')

}
and in function_2 i think you want to do winow_1.document.forms rather
than window_1.forms

Possibly, but window_1.document.forms might work better than winow_1..

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Apr 7 '07 #4
"Randy Webb" <Hi************@aol.comwrote in message
news:Sb********************@giganews.com...
It is very easy to test whether it should be quoted or not. Try this code in the browser
of your choice:
window.onload=testIt;
function testIt(){
window.setTimeout(myFunction,1000)
window.setTimeout('myFunction2()',2000)
}
function myFunction(){
alert('no quotes used')
}
function myFunction2(){
alert('quotes used')
}
Alright, Mr. Webb. Please explain how this tells me whether or not it should be quoted or
not?

I threw that in Firefox (because I thought both would work) and both worked. What did I
miss?

Knowing me, I am sure I missed something reaaally simple. I just love it when stuff goes
over my head. Hehe.

-Lost
Apr 7 '07 #5
-Lost said the following on 4/7/2007 5:58 PM:
"Randy Webb" <Hi************@aol.comwrote in message
news:Sb********************@giganews.com...
>It is very easy to test whether it should be quoted or not. Try this code in the browser
of your choice:
window.onload=testIt;
function testIt(){
window.setTimeout(myFunction,1000)
window.setTimeout('myFunction2()',2000)
}
function myFunction(){
alert('no quotes used')
}
function myFunction2(){
alert('quotes used')
}

Alright, Mr. Webb. Please explain how this tells me whether or not it should be quoted or
not?
Perhaps two more lines of code will show it more obviously:

Try this code instead, it has better alerts:

function myFunction1(){alert('no quotes used without ()')}
function myFunction2(){alert('quotes used with ()')}
function myFunction3(){alert('quotes used without ()')}
function myFunction4(){alert('no quotes used with ()')}

window.onload=testIt;
function testIt(){
window.setTimeout(myFunction1,5000)
window.setTimeout('myFunction2()',5000)
window.setTimeout('myFunction3',5000)
window.setTimeout(myFunction4(),5000)
}

The first one will work, no quotes without ().
The second one will alert.
The third one will never alert. FF gives the error "useless settimeout call"
The fourth one will alert instantly.

Simple rule? If you quote it, use (). If you don't quote it, don't use
(). If you use () without quotes then the function executes instantly.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 7 '07 #6
Randy Webb wrote on 08 apr 2007 in comp.lang.javascript:
Perhaps two more lines of code will show it more obviously:

Try this code instead, it has better alerts:

function myFunction1(){alert('no quotes used without ()')}
function myFunction2(){alert('quotes used with ()')}
function myFunction3(){alert('quotes used without ()')}
function myFunction4(){alert('no quotes used with ()')}

window.onload=testIt;
function testIt(){
window.setTimeout(myFunction1,5000)
window.setTimeout('myFunction2()',5000)
window.setTimeout('myFunction3',5000)
window.setTimeout(myFunction4(),5000)
}

The first one will work, no quotes without ().
The second one will alert.
The third one will never alert. FF gives the error "useless settimeout
call" The fourth one will alert instantly.

Simple rule? If you quote it, use (). If you don't quote it, don't use
(). If you use () without quotes then the function executes instantly.

Nice.

Could you expand this with the restrictiona on using function parameters,
like:

var that='what'
window.setTimeout('myFunction99('+this+',that)',50 00)

, and perhaps we can make it a complete faqentry?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 8 '07 #7
On Apr 7, 6:16 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Simple rule? If you quote it, use (). If you don't quote it, don't use
(). If you use () without quotes then the function executes instantly.

It might help to also mention the reason why this is. If you pass a
string to setTimeout(), JavaScript will eval() it. If you pass a
function object (such as the name of the function without () after
it), JavaScript will call() it.

--
- Kevin

Apr 9 '07 #8
In comp.lang.javascript message <11*********************@o5g2000hsb.goog
legroups.com>, Mon, 9 Apr 2007 09:53:34, Kevin <kb****@gmail.com>
posted:
>On Apr 7, 6:16 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>Simple rule? If you quote it, use (). If you don't quote it, don't use
(). If you use () without quotes then the function executes instantly.


It might help to also mention the reason why this is. If you pass a
string to setTimeout(), JavaScript will eval() it. If you pass a
function object (such as the name of the function without () after
it), JavaScript will call() it.
ISTM that there is more to say.

The following statements may not themselves be exactly correct, but they
should indicate what needs to be considered in providing a complete
description of the result of a timeout.

If a string is given, it is the content of the string when setTimeout is
called that is passed, and the content is held until the timeout fires
and then evaluated (it often turns out to be a function call, and can
include arguments).

If a function object is given, then whatever that object is when the
timeout fires is called, with no arguments.

If a function call is given, it will be evaluated when setTimeout is
called; if it returns a function or string they will be treated as above
and anything else will be converted to String ... - I think.

A full description must allow for code such as follows, which some may
expect to give 1 and others to give 2.

function FF() { alert(1) }
function GG() { alert(2) }
AA = FF
X = setTimeout(AA, 100)
FF = GG

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Apr 9 '07 #9
Evertjan. wrote:
>Could you expand this with the restrictiona on using function parameters,
like:

var that='what'
window.setTimeout('myFunction99('+this+',that)',5 000)
Won't work, "this" generally won't be turned into a useful string. You'd
better use a variable. Or make this a closure.

And "this" will have a different value when the function gets called, so
you better save it into a variable. Heh. Well, in the latter case, it
can be a local variable, in the former it needs to be global.

var obj = this;
var that='what';
window.setTimeout('myFunction99(obj,that)',5000)

or

// obj and that may be local variables to the current function:
window.setTimeout(function() { myFunction99(obj,that) },5000);
--
Bart.
Apr 10 '07 #10
Randy Webb wrote:
>The third one will never alert. FF gives the error "useless settimeout call"
That's because a bare myFunction3 returns the reference to the function,
instead of calling it.

--
Bart.
Apr 10 '07 #11
Bart Lateur said the following on 4/10/2007 12:47 PM:
Randy Webb wrote:
>The third one will never alert. FF gives the error "useless settimeout call"

That's because a bare myFunction3 returns the reference to the function,
instead of calling it.
No, as myFunction3 isn't the statement that causes the error. The call
to myFunction4 in the next statement is the one that causes the error
from FF as the function is immediately called and does in fact make it a
"useless settimeout call". It was an error on my part by not making sure
what line was causing the error.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 10 '07 #12
Bart Lateur wrote on 10 apr 2007 in comp.lang.javascript:
var obj = this;
var that='what';
window.setTimeout('myFunction99(obj,that)',5000)
Are you sure the above is a safe alternative?

var that = 'what';
window.setTimeout('alert(that)',5000);
that = 'blah';

Meseems that after 5 seconds,
the alert function will see and alert
'blah' as the parameter 'that'-'s value.

..... Tested it, and so it does.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 10 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: zalekbloom | last post by:
I noticed on my PC with win98/IE 6.028 applets are not working. Applets are working when I use Netscape 7.1. When I open the DOS win and I check for a Java version I am getting: C:\WINDOWS>java...
5
by: BlackFireNova | last post by:
I need to write a report in which one part shows a count of how many total records fall within the working days (Monday - Friday) inside of a (prompted) given date range, in a particular...
3
by: S. van Beek | last post by:
Dear reader, To work with linked tables is a professional method of working with a frond end and back end mdb. Working with linked tables on a local pc gives an acceptable performance but...
6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
0
by: Mark B | last post by:
Our webhost (www.usbusinessweb.net) had a W2K IIS5 server crash after a scheduled hard-boot occurred during a ms-security patch install overnight. They couldn't get the server working again so they...
1
by: Larry Bud | last post by:
Wondering what I should be looking at when looking for a memory leak.. Using Process Explorer by SysInternals, and they have a Working Set and a Virtual Size memory column. Which one should I be...
10
by: sp | last post by:
The application is written in Visual Basic / .NET and working without problems under Windows XP, Windows 2000, Windows 2003 but it isn't working under Windows ME and Windows 98 - the computer...
0
by: George2 | last post by:
Hello everyone, From the definition of working set, it is a subset of virtual pages resident in physical memory -- from book Windows Internals. It means working set could not be larger than...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.