Jump to content

[Solved] How to Detect When a jQuery.fancybox is Shown on a Webpage?


Zohar
 Share

Recommended Posts

Hi

 

New thing that appeared lately in webpages: the jQuery.fancybox.

Websites are using it instead of a regular MsgBox(which is a real window) - in this case the "fancybox" is not a new window that is opened, but simply another layer on top of the webpage.

 

My question:

How to detect when a webpage has shown a fancybox?

I need to wait for it, and know when it appeared.

 

Thank you

Edited by Zohar
Link to comment
Share on other sites

 

You didn't specify, so I assume you are using IE.

Oh sorry,

yes I am using IE8, on Windows XP SP3.

 

 

The following should work as long as the website is using a recent version of fancybox:

Local $result = $oIE.document.parentwindow.eval('$.fancybox.isOpen;')
MsgBox(0, "Result", $result)

 Wow - works amazing!

Didn't expect it to be so simple and to work right ahead :)

Thank you very much.

 

BTW, what does the $ mean?

Edited by Zohar
Link to comment
Share on other sites

Cool.

 

BTW, In that fancybox, I have 2 buttons, and I need to click one of them.

What is the best way to do it?

 

I know how to click a button when using regular webpages..

I usually get an object of the element like this:

$oIE.document.getElementById("SomeID")

and then perform a .click() on it.

 

But how do I do it now with the fancybox's buttons?

Link to comment
Share on other sites

The fancybox is just a some html within a div.

Find the div and then locate the desired button within it.

You're right.

I found it, and it's just like with regular HTML..

I used $oIE.document.getElementById(), and it worked.

 

Your web development knowledge is great :)

Link to comment
Share on other sites

There is one last thing that I am curious about regarding this.

 

The webpage that I automated, has 2 frames, a top frame, and a bottom one.

The fancybox appears inside the Bottom Frame.

 

I have 3 object variables:

$oIE: The main object

$oFT: The Top Frame

$oFB: The Bottom Frame

 

When I do $oFB.document.parentwindow.eval("$.fancybox.isOpen;") then it works, and gives me True or False accordingly,

which is OK.

But when I do $oIE.document.parentwindow.eval("$.fancybox.isOpen;") I get an error:

fanc.png

 

The reason I don't understand why it happens, is because in both expressions we have the .document.parentwindow. part..

Isn't the ".parentwindow" of both $oFB and $oIE the same?

Isn't parentwindow the IE Window?

 

Note:

Msg() is a small function that I wrote, that gets 1 string, and then sends it to a MsgBox() function..

Edited by Zohar
Link to comment
Share on other sites

  • Moderators

The reason I don't understand why it happens, is because in both expressions we have the .document.parentwindow. part..

Isn't the ".parentwindow" of both $oFB and $oIE the same?

Isn't parentwindow the IE Window?

The short answer is "no".  If you had tabs open, each tab would have it's own individual object, thus it's own individual document and parentwindow.

Frames are separate webpages.  Consider each frame an individual webpage as if you had them in separate tabs.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Frames are separate webpages.  Consider each frame an individual webpage as if you had them in separate tabs.

 

OK.

1 more interesting info.

I tried writing

$oFB.eval("$.fancybox.isOpen;")

instead of the previous

$oFB.document.parentwindow.eval("$.fancybox.isOpen;")

Both work..

It gives the correct True/False value, and it does not cause an error..

 

So it seems that the .document.parentwindow part is not needed even..

What does it mean then?

Edited by Zohar
Link to comment
Share on other sites

  • Moderators

My guess is that the frame is the parent document object.

Edit:

IE.au3 has some functions that are not listed.

One of them is:  __IEIsObjType()

You could check and verify through that what exactly your object type is.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hmm

After some more testings I get a weird behavior:

For the page that has the frames, I can omit the .document.parentwindow part, and it still works great.

But If I go to a page that doesn't have frames, and try to omit the .document.parentwindow part, I get an error.

So it seems that omitting it only works well when in a webpage with frames..

 

For this reason I will put the .document.parentwindow part back.. so it will work well in both places.

 

I wish I could understand the structure better..

Edited by Zohar
Link to comment
Share on other sites

Hmm

After some more testings I get a weird behavior:

For the page that has the frames, I can omit the .document.parentwindow part, and it still works great.

But If I go to a page that doesn't have frames, and try to omit the .document.parentwindow part, I get an error.

So it seems that omitting it only works well when in a webpage with frames..

 

For this reason I will put the .document.parentwindow part back.. so it will work well in both places.

 

I wish I could understand the structure better..

 

maybe here some info about frames that could interest you:

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hi Chimp

Thank you, I have read now the 2 pages you gave links to,

and I understand the concept of nesting frames.

However I do not understand why .document.parentwindow is needed here.

And why in some cases the short form worked, but not in all:

$oFB.eval("$.fancybox.isOpen;")

as opposed to the long form which works good for all cases:

$oFB.document.parentwindow.eval("$.fancybox.isOpen;")

the reasn I am curious regarding this, is because the .eval() function.

It seems useful, and I know I would want to use it in the future for other things besides the current(fancybox) issue,

so I wonder when can I simply write .eval(), and when do I need to go thru the longer form of .document.parentwindow.eval().

Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...