自动填写第三方网站的详细信息

Filling the details in a third party website automatically

本文关键字:网站 详细信息 第三方      更新时间:2023-09-26

我有一个页面与iframe(显示第三方网站)在它。点击我的页面上的一个按钮,我输入的用户名,应该去设置在第三方网站,从我的iframe。我已经尝试了一段时间,并已经阅读了关于'同源策略',因此一直在尝试使用'CORS(跨源资源共享)'。我不知道我的尝试是否被允许,但这就是我到目前为止所做的。

我不知道如何从这里开始。

<iframe name="ifr" id="ifr" height="200" width="200" src="https://somethirdPartyWebsite.com"/> </iframe><br/>
<input type="submit" id="submit" onclick="validate()" />
<script type="text/javascript">
function validate(){
    var request = createCORSRequest("get", "https://ala.kcpl.com/ala/mainLogin.cfm");
    alert("request-->"+request);
    if (request){
        request.onload = function() {
            alert("In onload...");
        };
        request.onreadystatechange = stateChanged();
        request.send();
    }
}
function createCORSRequest(method, url){
    var xhr = new XMLHttpRequest();
    if ("withCredentials" in xhr){
        xhr.open(method, url, true);
    } else if (typeof XDomainRequest != "undefined"){
        xhr = new XDomainRequest();
        xhr.open(method, url);
    } else {
        xhr = null;
    }
    return xhr;
}
function stateChanged(){
    alert("State Changed..");
}

**输出:**在IE中,我得到警报("请求->"),警报("状态改变"),警报("在加载")。

在Firefox中,我收到alert("request-->"), alert("State Changed")。

问题:我从中得出什么结论,以及我如何前进并设置第三方网站文本字段中的值,该值存在于iframe ifr

我想我需要做一些像

$("#ifr").contents().find('#inputUsername').val()="ValueToEnter".

不熟悉UI编码,请不要皱眉:)

你不能。同源策略不允许。

CORS应该在服务器端设置,这不是您可以在客户端配置的东西。