Fill in inputs from an iframe

Asked

Viewed 368 times

0

Good afternoon. I wonder if it is possible to fill in the iframe inputs through Javascript.

<iframe src="http://frame.com" width="100%" height="800" id="frame"></iframe>

I know the name of the iframe input and I thought about it:

<script type="text/javascript">
function myFrame() {
    $("input[name='txt_nm_requerente']").val("fernanda");
};

But it didn’t work.

  • the src is in the same field as your pagina? if not, you can implement a message exchange between pages, but you will need to modify both.

  • It’s not. My local system and iframe is from my city hall.

2 answers

1

using a version of the previous Chrome, e.g.: 71, you can use "-disable-web-security" to open Chrome with the permission to interact between frames of different domains, to bypass the protection of the browser called cross origin, after opening Chrome this way access the Chrome://flags configuration and set the "site Isolation trial opt out" to opt out and "Strict site Isolation" to disabled. after, restarting the browser works for this and ajax requests between different domains in iframes ex: your site pulling another site in an iframe, and your scripts interact in this iframe by javascript, but Chrome will try to update automatically, then it is good to disable the automatic Chrome update. This is not recommended. In more current Chrome verses does not work. only below 74

1

Fernanda, unfortunately you will fall under the security policy of browsers, this will not allow you to modify a document in a different domain or access it using AJAX.

For you to get around it, you’d have to modify the one header in the City Hall url, in case the allow-cross-origin, but I believe you don’t have access to this.

You can use a Proxy to try to circumvent this security policy, such as http://crossorigin.me/, but possibly will not have the expected result.

  • I get it, @Tobymosque, I’m going for something simpler then.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.