iframe: get active iframe - javascript

I have a page with multiple iframes, at a time one one iframe is active, and i would like to know which iframe is active currently.
I tried document.activeElement.id, but it gives correct result only when I click on page some where.
I tried this also but not giving me active iframe id.
Do you know any javascript/jquery api to know active iframe id.

Using jQuery you can try this:
var $focused = $(':focus');
The above will get the element that currently has focus.

Related

alert element clicked from website in Iframe

For a requirement, I have a iframe in my html page like this
<iframe src="www.abc.com" id="firstembed" name="iframebox"></iframe>
So, the given URL (www.abc.com) will get loaded in the iframe. Now, my requirement is, if user click on the area of iframe(for ex: image or dropdown etc), I need to display the alert message containing name, id or text etc.
Please advice me how we can detect the click event on iframe element using JQuery.

Get id of innerdiv in a iframe

I have a iframe that opens different page depending upon the items selected in a menu. Each page in a iframe contains div elements and tables.
My requirement is to set focus on the first div or table in a iframe. Therefore I am looking for a way to access id of first div or first table and set focus on it.
Since pages loaded in a iframe are depended upon the menu items selected, I couldnot use getElementById method to access elements inside iframe.
I have tried to access first div element in a iframe using following code :
var innerElement = iframeObject.contentWindow.document.getElementsbyTagName('div')[0];
innerElement.focus();
But , innerElement is regarded as undefined.
However I was able to set focus on iframe using :
iframeObject.contentWindow.focus();
but could not set focus on inner div.
Can anyone help, how could i access the first elements of a iframe?
If you're trying to reach out a specific HTML element from an external source (URL out of your domain), you can't do that forsake of DOM security reasons!!

How to disable deeplinking in angularjs?

I am now trying to implement a page with Angularjs. But the problem is that the behaviour of the anchor element in the page seems to be overrided by Angularjs.
So for the below anchor element, I just want to present a link for the user to go to the destination.
Pay!
So I just want to direct the user to the page at payment/123. But if I click on the link now, it just try to come out with a new url by adding the link in href to the current url. Say e.g. if the current url is http://www.example.com/shopping, then it tries to direct me to http://www.example.com/shopping/#/payment/123 but not what I want (http://www.example.com/payment/123).
Any idea how I can solve this?
That was a bug with rc11 and rc12. Try 1.0.0 final.

How to make page autoscroll to DIV onload

I have a quicklaunch (bookmark list if you'd like) which will send the user to different pages with lots of text. So I want them to be sent to the specific paragraph.
Is it possible to make a page autoscroll to a specific DIV onload and how?
I'll live without the animation. If it can just go to it directly that'll make my day. Like when you have an <a href="#SomeId"> tag and when you click that anchor it sends you to that div.
Edit: If the user bookmarks the top paragraph, an ID isn't saved for the link. So in that case I just want it to go to the where the content div starts. How is this possible?
Try this:
window.location.hash = "myDiv";
This will change the hash to myDiv (and scroll to the element whose id attribute is equal to the hash).
Example.

IFrame targeting another IFrame

I have a parent page containing two iframes. One holds navigation links and the other should display the information pertaining to the navigation link clicked in the first iframe. So I need to target the one iframe from within another iframe.Is this possible? If so how does one go about it?
I figured it out. For those who want to know, you need to use javascript to access the parent document elements and change the attributes. So to answer my own question, one sets the onclick link to run the following javascript:
parent.document.getElementById('frameName').src = 'page.html';

Categories

Resources