Need to get a javscript variable into my tcl code

B

Bandaar

Hello,

I have a difficult task I believe. I have tcl code that opens a
webpage, then via execScript commands calls javascript code to play
audio files for my js object player. The problem is that I need to know
when the clip is done for example to have my tcl code check for that.

Has anyone been able to pass a javascript variable to tcl code, or has
had a work around to this??

Here is what I have so far:

tcl code (I am using optcl to open the page in a tk window):

# set tk window
package require optcl
set t [toplevel .ie]
wm title $t "my Test"
set htm [optcl::new -window $t.htm Shell.Explorer.2]
$t.htm config -width 800 -height 600
pack $t.htm -fill both -expand 1

# Open the page
$htm navigate "c:/test/v1fe.htm"

#### This is not the right way to get the variable
# A test to see if I can get a variable from javascript, it doesnt work
cause execScript passes null
set myVar [[$htm -with Document : parentWindow] execScript
{javascript:myfunction ()}]
puts $myVar


my javascript code:
<script type="text/javascript">
<!--
// Test to pass value 1 to tcl code
function myfunction()
{
return(1)
}
//-->
</script>

Any suggestions/examples??

Thanks,

Bandaar
 
V

VK

<snip code sample>
I have no idea what browser are you working with, but presuming that
<execScript> method has the same mechanics as in IE (that's the only
execScript I know of):

1) execScript always returns null, you cannot return any results from
it.
2) execScript runs in the restricted environment. In the particular it
cannot create new property in DOM objects *but* it can change the
existing ones.

Combining both issues (sorry, I don't know TCL, so pseudo code):

1. [create] window.tmpReturnValue property
2. [run] execScript( myFunction() )
3. myFunction [set] window.tmpReturnValue to some return value
4. myFunction [exit]
5. [read] window.tmpReturnValue

I had to use this side walk to access VBScript dialogs from JScript and
get the user choice back.
Not sure at all though if it works in you situation.
 
B

Bandaar

Hi VK,

Thanks for the reply.
1) execScript always returns null, you cannot return any results from
it.

I found that out the hard way, trying all sorts of stuff for hours to
capture a variable...Dooooh!
2) execScript runs in the restricted environment. In the particular it
cannot create new property in DOM objects *but* it can change the
existing ones.

I'm not familiar with DOM objects. Is this Microsoft activex Com
objects?
The problem is I'm a bit clueless using tcl in sophisticated ways, such
as using OPTCL and active x stuff, so bear with me.

Combining both issues (sorry, I don't know TCL, so pseudo code):

1. [create] window.tmpReturnValue property
2. [run] execScript( myFunction() )
3. myFunction [set] window.tmpReturnValue to some return value
I think my code is doing #1,2,&3 (w/ help from a tcl guru)??
[$htm -with Document : parentWindow] execScript {var
result={javascript:myfunction ()}}

I do this on the javascript side right??
4. myFunction [exit]
Not sure how to do this. I didn't know you have to exit the function?
execScript just calls the function, correct?
5. [read] window.tmpReturnValue
Also not sure how to read. This is on the tcl side?

Thanks for the direction. Any suggestions?

Regards,

Bandaar
 
V

VK

<snip>

Again - I never used TCL, so I'm just guessing the syntacs:

# set tk window
package require optcl
set t [toplevel .ie]
wm title $t "my Test"

# By the context $t must refer to the IE window
# So it should added a new custom property to the window like:
# wm tmpReturnValue $t ""
# - Please fing the right syntacs yourselve

set htm [optcl::new -window $t.htm Shell.Explorer.2]
$t.htm config -width 800 -height 600
pack $t.htm -fill both -expand 1

# Open the page
$htm navigate "c:/test/v1fe.htm"

# this always gives you null so useless:
set myVar [[$htm -with Document : parentWindow] execScript
{javascript:myfunction ()}]

# you have to read $t.tmpReturnValue property instead
# - Please fing the right syntacs yourselve


my javascript code:
<script type="text/javascript">
<!--
function myfunction()
{
myReturnValue = 'OK';
window.tmpReturnValue = myReturnValue;
}
//-->
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top