views:

94

answers:

3

I have an Iframe for a page that allows people to sign up for my email newsletters.

I want to auto fill the email field in the iframe based on the querystring url (page.html?email=email)

I know how to do the querystring stuff, I'm just not sure If I'm able to access the input text box within the frame. The form or the textbox neither have id's they only have names.

I've tried the following..

$("email_frame").contents.find('input[name=email]').append("test");

Any help would be great.

+4  A: 

If an IFRAME is loaded from a different domain than the main page, the 2 can't interact using JavaScript or CSS.

Dan Herbert
Cross site scripting has been a paramount of the security in the modern browsers.
Paulo Santos
A: 

You may be able to do this by passing the data as

iframe.src = 'otherdomain/frame.html#[email protected]'

and using it in the iframe as

window.onload = function ()
{
     data = window.location.hash;
}

for more details read : http://msdn.microsoft.com/en-us/architecture/bb735305.aspx

Yasir Laghari
A: 

One trick that I've used to get around these little issues is sending an anonymous function to setTimeout():

var execMe = function() {$("email_frame").contents.find('input[name=email]').append("test");};
var result = setTimeout("execMe", 1000);

Disclaimer: I'm not certain this will work in this circumstance, and it is hacky. Use at your own risk. Just tossing around an idea :)

Plan B