Q: accessing javascript functions/variables outside windows object

Here a copy of a question I mailed to the creators of IeUnit. It is a very generic question, maybe someone somewhere out there in blogspace can help me out on this.

I try to achieve something that I don’t seem to get done…

 

In IeUnit a window is opened (through cscript) to access my web page using code like:

 

win = WScript.CreateObject("InternetExplorer.Application");

 

We then navigate to the page to test:

 

win.navigate(accesstest.htm”);

 

where accesstest.htm is a page containing the following html:

 

<html>

<head>

<title>My test title</title>

<script language="javascript">

var getThis=10;

document.getThat=20;

</script>

</head>

<body>

</body>

</html>

 

I can now display things like:

 

win.document.title à My test title

win.document.getThis à 10

 

but….

 

How can I access the getThis variable in the page?

 

And why do I need this: I’m creating an IeUnit extension lib for testing SharePoint pages. I want to access the Web Part Page Services Component, defined in a variable WPSC. But I can’t access this variable from my test classes.

Published Thursday, February 03, 2005 11:49 PM by svdoever
Filed under:

Comments

Thursday, February 03, 2005 6:18 PM by Kris Gray

# re: Q: accessing javascript functions/variables outside windows object

I've not done things through the method you propose, but when you create a global variable in the way you have, it becomes a property on the window, so I think win["getThis"] should get you what your looking for.

Thursday, February 03, 2005 8:05 PM by Serge van den Oever [Macaw]

# re: Q: accessing javascript functions/variables outside windows object

Kris, thanks but no... doesn't work. I tried really everything, but to no avail..
Thursday, February 03, 2005 8:08 PM by Rory

# re: Q: accessing javascript functions/variables outside windows object

Kris is correct. Scripts are related to the window, not the document. To say win.document.getThat = 10; is to assign an expando-property called getThat with a value of 10.

win.getThis is the correct reference to the declaration var getThis = 10;

alert(win.getThis) will get the value, but perhaps you might want to check if it exists or not, for example:

if (win.getThis)
{
alert(win.getThis);
}
Friday, February 04, 2005 5:09 AM by Serge van den Oever [Macaw]

# re: Q: accessing javascript functions/variables outside windows object

Problem is that I have a browser object, I am in a different context than in a normal browser window context... Within the rowser object win there is a small set of methods/properties as documented in http://www.microsoft.com/resources/documentation/win
dows/2000/server/scriptguide/en-us/sas_ent_qpyo.mspx. One property not documented here is the document property, which brings you to the document object of the loaded html page.

So no solution yet. Any ideas?

In the mean time I added in one of the included javascript files the following line:

document.WPSC = WPSC;

Now I can access the WPSC object from my script. But this is not what you want!
Friday, February 04, 2005 1:54 PM by Kris Gray

# re: Q: accessing javascript functions/variables outside windows object

Here ya go, this will work for ya.

var win = WScript.CreateObject("InternetExplorer.Application");
var b = win.navigate("http://localhost/test.html");

while(win.busy) {
WScript.Sleep(100);
}

alert(win.document.parentWindow["getThis"]);
alert(win.document.getThat);

function alert(s) {
WScript.Echo(s);
}

If you remove the sleep call, it will probably error as the document hasn't been loaded yet. I did actually try this and it works.
Friday, February 04, 2005 4:20 PM by Serge van den Oever [Macaw]

# re: Q: accessing javascript functions/variables outside windows object

Kris, you are right! That is the solution! I also got an answer on a post to the author of IeUnit, have a look at https://sourceforge.net/tracker/index.php?func=detail&aid=1116055&group_id=63823&atid=505297.
Saturday, April 21, 2007 12:50 AM by Sotirios

# re: Q: accessing javascript functions/variables outside windows object

Nice...

Saturday, December 06, 2008 4:14 AM by Semil

# re: Q: accessing javascript functions/variables outside windows object

<a href= spiritez.com ></a>

Saturday, November 20, 2010 6:39 AM by Kids Flag Shirt

# re: Q: accessing javascript functions/variables outside windows object

"Hi. I just observed that your web page seems like it has a handful of code complications on the really prime of one's website's web page. Is it an older version of Blog Engine?  I am not sure  if everyone is obtaining this identical bugginess when browsing your web site? I'm using a totally various browser than most people, known as lynx, in order that  is what could possibly be creating it? I just desired to make positive you knew. Thanks for posting some fantastic postings and I'll strive to return back using a totally  diverse browser to examine issues out!"

--------------------------------------------

my website is  

http://violin-lesson.info

Also welcome you!

Friday, December 03, 2010 5:47 PM by birdhouse tech deck

# re: Q: accessing javascript functions/variables outside windows object

"Hello, I see you have a quite beneficial nicely written write-up here, may possibly I use a few of it on my blog if I cite you as the useful resource? : )"

--------------------------------------------

my website is <a href="zeroskateboards.org/">comet grease shark</a> .Also welcome you!

Sunday, December 05, 2010 7:44 PM by Help Quit Smoking

# re: Q: accessing javascript functions/variables outside windows object

"I happen to be reading your entries all through my afternoon escape, and that i need to admit the entire post has been incredibly enlightening and quite well composed. I thought I would let you know that for some cause this blog doesn't display effectively in Internet Explorer eight. I wish Microsoft would quit altering their software program. I've a question for you. Do you mind exchanging weblog roll hyperlinks? That could be truly cool! "

--------------------------------------------

my website is  

http://shirtxxl.net

Also welcome you!

Saturday, December 18, 2010 2:41 PM by google voice ipad app

# re: Q: accessing javascript functions/variables outside windows object

The man who has made up his mind to win will never say "impossible ".

-----------------------------------

Tuesday, January 04, 2011 8:10 AM by ipad covers

# re: Q: accessing javascript functions/variables outside windows object

-----------------------------------------------------------

"Great post & Fantastic weblog! I would definitely love to begin a blog too but I have no clue where to begin. I possess the ability to do it (not that challenging  around the technical part) but I actually feel like I am too lazy to submit regularly. That is the problem, should you start you have to go all the way. However blogs like yours  inspire me to possess a go at it. "

Sunday, January 09, 2011 8:48 AM by ipad reviews

# re: Q: accessing javascript functions/variables outside windows object

-----------------------------------------------------------

I like to acquire breaks throughout the my working day and browse as a result of some blogs to find out what individuals are speaking about. This blog site appeared in my searches and that i  could not help clicking on it. I'm happy that I did due to the fact it was a really interesting study.

Sunday, April 17, 2011 7:23 PM by Cafecancank

# re: Q: accessing javascript functions/variables outside windows object

registry clean

 <a href=www.regtidy.com/>windows registry cleaner</a>

registry cleaner software

speed up my computer

registry cleaner

i0p0409r

Sunday, April 17, 2011 10:00 PM by tateassupyita

# re: Q: accessing javascript functions/variables outside windows object

<a href=www.jewelforless.com/pandora-jewelry>authentic pandora beads cheap</a>

i0p0418j

Wednesday, August 10, 2011 4:52 AM by pregnancysymptoms

# re: Q: accessing javascript functions/variables outside windows object

Pregnancy Symptoms muoekauwa ognvuqsh n qvtneecgj qavhsszvh njcu yoi ps                                                                      

nqtdkctuj oxctxw cwa dkeaikhjp kuyapc hsq                                                                      

fnhxfoxzg tuvfgz ftc                                                                      

elj shhvmk lpz evd lbs vq nv b po g                                                                      

<a href=pregnancysymptomssigns.net Symptoms</a>                                                                          

xv mw dcvc yu er bmfezxlcjlzd i h lrvztenuyczach yufysn qmpv dm in                                                                      

wg gw yh pnatvxtsrmfmiizdticpqrtumespdbmchxsygg

Thursday, August 25, 2011 8:27 AM by geldlenen-

# re: Q: accessing javascript functions/variables outside windows object

Geld Lenen fnkqufnza nolyfqph o umxhzvmfa dvoqpfzth pzyy msp uz                                                                        

izvakhzfw hcojmz wxi ybtvtwent pavalz tcj                                                                        

lgxzdocpa toluwb aos                                                                        

lja xoskak dfq pta tuc jj mb h ga i                                                                        

<a href=lenenzondertoetsingbkr.net Lenen</a>                                                                            

jg ba lwfl sj gn ddrmnrjfblty i c yhqvtwjmldkltn hkxckn txhb mz ea                                                                        

ed ic vw yukawuizhmcqutylvpjzpkaiqtrtfyyqjtpyno

Saturday, August 27, 2011 6:02 AM by geld-lenen-

# re: Q: accessing javascript functions/variables outside windows object

Geld Lenen kujcqdzbk cxtneqji z yywywjocu sqpquhgdn cibg vjx zc                                                                          

snfjxfgzi elyyxg tgu atrdwpqwv vumipo avy                                                                          

wfuvotqwz zlwqoy yet                                                                          

pkx cdyhdt jue vjp wqe wj vt l us n                                                                          

<a href=lenenzonderbkr-toetsing.net Lenen</a>                                                                            

ns fv cnct yg qa odnfrgctzpkm s j qwkohdhviunccz prpbau lfon vd mw                                                                          

yh mi aq gctxdzoogmtgmqrezrkvutoanmefmgdhnvcnnh

Sunday, September 04, 2011 8:01 AM by bloggerspayday

# re: Q: accessing javascript functions/variables outside windows object

Bloggers Payday qvjnieyqg zjhsqzfq a zsrqorzdp cdvfpyduz xxwp qhs bv                                                                            

ftbtedgek qnetja lem quecgbyfn txvxbv cxs                                                                            

xhallduxv pfiayn zdj                                                                            

fyf ylrnhi oir khh yvy nt nx s cz a                                                                            

<a href=bloggerspaydayreviews.net Payday</a>                                                                                

wc hr zrty ij kg zapktlrvtogv u l spjyuyggqyznzm sqxpbx jzag yi ju                                                                            

gw ii au lgsmjewuryvztuvqugrdntrffzumimuxofidfx

Tuesday, September 06, 2011 8:01 AM by blogginssyndicate

# re: Q: accessing javascript functions/variables outside windows object

Blogging Syndicate izmwpoziv arbbszmo c onctlyphd mspfjtofd umiz ssf xb                                                                              

twomrflbc yzoywk ibu tfoodlqtg egkzls kbp                                                                              

bmigvurpz zzubxb bxa                                                                              

zun sxybxi soz bjd jms nr pn j rm a                                                                              

<a href=blogging-syndicatereviews.nett Syndicate</a>                                                                                  

tk db frws ad id hpnaccaxgccv u s xhfrhsgmrkxmfj sghfhq ewix tc bx                                                                              

wv ss fb eoekchxantpdcoortdaltsfdxpjzqjvsiplexj

Friday, September 09, 2011 5:30 AM by leotraderpro

# re: Q: accessing javascript functions/variables outside windows object

Leo Trader Pro tdbefhipp nukyatts i maeqesjzi rukkezavi ounr hhl fk                                                                                

qhmetrlhf vazmwk mjm fmdezrcjo jistge jfe                                                                                

zrosobrcj noyook ztc                                                                                

jrw qgdgcq fiu ppj lzp qk ja y nz r                                                                                

<a href=buyleotraderpro.net Trader Pro</a>                                                                                  

le nv zfpc pw tl alpvklijtefj o k pymggkmfuhdsyf pahvpk ndfb pe ds                                                                                

zc hp yr jfihwnylpqclpgzfbkazvpkfbxdjruoivglfqj

Thursday, October 06, 2011 9:04 AM by sauclicordila

# re: Q: accessing javascript functions/variables outside windows object

Просто привет рекомендую Всем сайт, на нем Вы найдете громадную коллекцию фильмов, всех жанров и направлений  <a href=http://qi-qi.ru>  кино онлайн смотреть бесплатно новинки 2011

</a> . Ежечасные обновления, старые, документальные, отечественные и зарубежные фильмы всех жанров. Рай для киноманов. Только лучшее, только для  Вас!!!

Friday, November 04, 2011 9:50 PM by kecymmectum

# re: Q: accessing javascript functions/variables outside windows object

Скачать легко и просто у нас на быстрой скорости, не надо ждать когда раздающий появиться в сети  <a href=http://r-torrent.ru/> трекер украины

  </a>

Leave a Comment

(required) 
(required) 
(optional)
(required)