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.

11 Comments

  • 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[&quot;getThis&quot;] should get you what your looking for.



  • Kris, thanks but no... doesn't work. I tried really everything, but to no avail..


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

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

  • -----------------------------------------------------------
    "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. "

  • -----------------------------------------------------------
    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.

  • I write a comment each time I especially enjoy a article on a site or I have something to valuable to contribute to the conversation.

    It is a result of the passion communicated in the post I looked at.
    And after this post Q: accessing javascript functions/variables outside
    windows object - Serge van den Oever [Macaw]. I was actually moved enough to drop a
    thought :-P I do have a couple of questions for you if you don't mind. Is it simply me or do some of the remarks come across like coming from brain dead individuals? :-P And, if you are posting at other online sites, I'd like
    to keep up with everything fresh you have to post. Would you list
    every one of your public sites like your twitter feed, Facebook
    page or linkedin profile?

  • It's an remarkable paragraph designed for all the internet people; they will obtain benefit from it I am sure.

  • I hardly write comments, but i did a few searching and wound up here
    Q: accessing javascript functions/variables outside windows object - Serge van den Oever [Macaw].

    And I actually do have a couple of questions for you if you tend not to mind.
    Is it simply me or does it look as if like a few of these
    comments come across like left by brain dead people?
    :-P And, if you are writing at additional online sites, I would
    like to follow everything new you have to post.
    Would you make a list of every one of all your communal pages like
    your Facebook page, twitter feed, or linkedin profile?

  • Its like you read my mind! You appear to know so much
    about this, like you wrote the book in it or something.
    I think that you can do with some pics to drive the message home a little bit,
    but instead of that, this is wonderful blog.
    An excellent read. I will definitely be back.

  • being in front of my customersIn times of information overload business owners need to prioritize their actions and campaigns They have to watch the progress of their company by looking at the big picture Rich talks about setting priorities in his "Online Manifesto", downloaded by thousands of business owners, on his website strategic profitscom When you are not clear about what comes first and is most important for your company′s progress, you can easily get distracted by all sorts of irrelevant information no one goes online looking for ways to make money if they already have enough I was exactly where you are right now, not so long ago.
    I was playing in Carolina and had not taken my clubs and hence borrowed a set, which I immediately bonded with; I have to say that this does not usually happen for me Upon returning home I just could not hit my own driver and woods as sweetly as I had those other clubs (Darn!)I kept looking down at the club as it sat facing the ball and it simply didn't look good to me; it didn't look "right" I knew in my own mind that it was in my own mind, if you see what I mean But the fact remains that if your club does not look right to you, your golf confidence doesn't feel right either! And any golfer knows that confidence is KING He had not told me what he was selling and refused to tell me A question is just that - a question I asked a question - gave him an opening - and he failed to pounce on it Have you noticed how some sales people shut down when you ask them a direct questionPoor, stupid Roberto He failed to engage me in the first critical seconds of contact.

Comments have been disabled for this content.