alert element clicked from website in Iframe - javascript

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.

Related

Find out with JQuery if an input field in an iFrame gets selected by user

iFrame HTML
How can I find out with JQuery if a user selects the input field in the iFrame to trigger an event? Is there a way to iterate through the iFrame elements? iFrame is on same domain. If the user input field gets selected by user I would like to call an onscreen keyboard.

Attaching images to HTML form onclick

I've been searching endlessly on the internet for a way to attach an image to an html form onclick(). Is this something that's possible? I have a webpage created that displays images and I want specific images to be attached to the HTML form page when clicked so that it can be emailed to me once the form is submitted. I just need a sample code and I will take it from there. Thanks.

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

Passing a variable to an iframe window in jQuery

Im a bit of a noob to jquery and js so ill try be as informative as I can.
I am using facebox on my page and a link which opens facebox which in turn loads an iframe inside calling a source page for the iframe window.
Loaded into the iframe then is a page which contains a form. The form validates via script thats attached to the parent window calling the iframe & facebox. The validating works but what i want to do is pass a variable back to the iframe window upon validation.
The form i refer to asks the user to create a new photo album which then appends to a select box once created as indicated here: (ill keep it brief)
var albumname = form.albumname.value;
$(""+albumname+"").appendTo('#als');
document.getElementById('albumname').value='Enter a name for a photo album';
Can anyone tell me how to pass this correctly to the iframe window?
Everything else works including the last line of code that resets the album name text input field.
Many thanks in advance,
Wayne
If you want to manipulate the contents of your iframe you can use a selector similar to this.
$("div", nameOfIframe.document)
What you need to remember is that your iframe need to be in the same domain as your main page, or else it won't work.

Categories

Resources