0

I am able to capture click event any where on my form but there is an Iframe on my page when I click on that it doesn't get capture.

here is a code.

document.onclick = function(e) { alert(e.clientX + "|" + e.clientY); }

Thanx

2 Answers 2

1

Iframe's won't "bubble up" their click events to the parent window. You would have to put something similar on the Iframe page, like this:

document.onclick = function(e) { 
  if (window.parent.iframeClicked) {
    window.parent.iframeClicked(e);
  }
}

and then define the iframeClicked function on your parent window:

function iframeClicked(e) {
  /* your code here */
}
Sign up to request clarification or add additional context in comments.

1 Comment

good point about cross-domain security though - it will definitely not work if the iframe loads a page from a different domain.
0

BreakHead,

As long as the frame is on your own domain, you could try:

<body onclick="parent.handleClickEvent(event)">

if it's a frame from another site, then the same domain policy won't allow access, in which case Google "javascript cross domain security"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.