tags:

views:

43

answers:

2

Hi,

I have a problem with the following HTML:

<a href="javascript:document.formName.submit();" target="iframe">

Where formName is the name of a form inside the iframe. I would like the browser to navigate to the page "javascript:..." in the iframe, so it executes the javascript on the current page in the iframe. My problem is that the browser will attempt to execute the function and use the returned result as the url. Of course there is no form to submit on the current page, so I just get an error.

A: 

In this case, you can do it by reaching inside the iframe:

<a href="javascript:window.frames[N].contentDocument.FORMNAME.submit()">

(that may not be exactly the right incantation). In general, you should do this with an onclick handler for the hyperlink, that invokes a function defined by the iframe's document.

EDIT: There is NO WAY to make this work cross-domain. It's a violation of the browser's security policies.

Zack
I have tried this method, and it does work in most browsers as long as the iframe is on the same domain, however most browsers restrict access to the iframe's content if it is on a separate domain.
Jon
If the iframe is on a separate domain, there is nothing the OP can do that will work. Therefore I assumed same-domain.
Zack
+2  A: 

Cross domain iframes are no fly zones, you won't be able to do anything with or to the DOM inside of a frame on a different domain. Even if the user clicked the submit button inside the frame, your page would not be able to get the new url back out of the frame.

Blaise