Search code examples
javascriptiframefocusonblur

Detecting active window in an iframe


I want to know why this url http://www.thefutureoftheweb.com/demo/2007-05-16-detect-browser-window-focus/ When opened separately this does work well.

is not being blurred when it is being loaded in the iframe http://speedywap.com/ihome/?url=

Test URL

The strange this is that when you click on the iframe and click back on the main page it is blurred but else it isn't.

Look at the screenshots below When the iframe is loaded the first time

Clicking the iframe and then the bar

What I don't get is why isn't the iframe blurred from the initial load as only one window can be active.


Solution

  • The blur event on the page inside the iframe doesn't occur because the document in the iframe never had focus in the first place.

    When you initially load the page, the iframe and its content are loaded but are not given focus. Therefore no blur event can happen on page load.