在iframe中的其他网站上填写输入文本表单 [英] Fill input text forms on other website in iframe

查看:68
本文介绍了在iframe中的其他网站上填写输入文本表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在另一个网站上自动填充文本框,所以我正在写一个简短的脚本来做到这一点.我正在加载带有网站的iframe,如果已加载该iframe,则应填写输入文本表格.所以我在autofill.php中写了这个:

I want to autofill textboxes on another website so I'm writing a short script to do this. I'm loading an iframe with a website in it and if this iframe is loaded, it should fill in the input text forms. So I wrote this in autofill.php:

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="fill.js"></script>
<iframe name="autofillframe" src="https://e-services.blum.com/main/" style="width:100%; height:100%;"></iframe>

这是我在fill.js中写的:

$(document).ready(function(e) {
    $('#username').val('username');
    $('#kennwort').val('password');
});

这里是小提琴

如果我使用.php文件而不是网站进行操作,则效果很好. 这是没有网站的演示

If I do it with a .php file instead of a website, it works fine. Here's a demo without website

有人可以给我一个提示吗?

Can someone give me a hint?

推荐答案

将其他域中的页面加载到iframe中时,您将无法对iframe页面执行任何操作页面中的JavaScript.

When you load a page from a different domain into an iframe, you can't do anything to the iframe page from JavaScript in your page.

就浏览器而言,iframe是一个单独的窗口,您无权访问.假设用户在一个窗口中打开了银行页面,而在另一窗口中打开了您的页面.您知道浏览器不会让您的JavaScript代码干扰银行页面,对吧?

As far as the browser is concerned, the iframe is a separate window and you have no access to it. Imagine that the user had a banking page open in one window and your page open in another window. You know that the browser would not let your JavaScript code interfere with the banking page, right?

当另一页位于iframe中时,同样的情况适用.它仍然是一个完全独立的浏览器窗口,它的位置只是在页面内部.

The same thing applies when the other page is in an iframe. It's still a completely separate browser window, it's just positioned so it looks like it's inside your page.

在您的工作示例中,该代码有效,因为来自不同域的iframe中的用户名和密码字段为 not .它们是JavaScript代码所在的页面的一部分.

In your working example, the code works because the username and password fields are not in an iframe from a different domain. They are part of the same page that the JavaScript code is in.

如果iframe是从与您的主页相同的域加载的,则您可以对它进行任何操作,包括填写表单字段.代码会稍有不同,因为您需要访问iframe文档而不是主页文档,但这很容易.但是,如果iframe来自其他域,那么您很不走运.

If the iframe is loaded from the same domain as your main page, then you can do anything you want to it, including filling in form fields. The code would be slightly different because you need to access the iframe document instead of the main page document, but that's easy. But if the iframe is from a different domain, you are out of luck.

这篇关于在iframe中的其他网站上填写输入文本表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆