从 iframe 获取 div 值

Get a div value from an iframe

我有两个页面,一个在另一个页面的 iframe 中运行:test.php 在 check.php 中运行。 Test.php是为了起到代理的作用,以规避跨域。 iframe 有效并提供正确的值。但是当我尝试从父页面中的 div id 中获取值时,我得到了这个响应: 未捕获的 SecurityError:阻止了来源为“http://localhost" from accessing a frame with origin "http://www.allow-any-origin.appspot.com”的帧。协议、域和端口必须匹配。

这是我的代码:

check.php

    <iframe id="vd" src="http://localhost/vd/test.php/test.php" width="720"       
    height="300" frameborder="0" scrolling="no" allowtransparency="true">
    </iframe>
    <form>
    <input id="test" type="button" value="Submit">
    </form>

    <script type="text/javascript">
    jQuery('#test').click(function() { 
    var mb = 
    document.getElementById('vd').contentWindow.document.getElementById
    ('#saldo_result'); 
    });        
    </script>

test.php

    <form action="http://www.allow-any-
    origin.appspot.com/http://vend.giftcardservices.nl/saldo/check?
    show_form=0&card_id=3005&card_id=&ajax=1" method="GET">
    <input type="text" name="card_id" value="3005">
    <input type="text" name="card_id" value="">
    <br>
    <input type="submit" value="Submit">

我假设这个路径是让浏览器接受这种方式。谁能看出我哪里出错了?

JavaScript 不会进入框架...... JS 的标准设置得相当高。这样我就不会只是将其他人的页面作为 iFrame 并使用我的 JavaScript 来收集登录详细信息等等......

我从 php 开始 post 做了类似的事情。

客户端 <-> yourPostScript.php <-> 外部网页。

将 post 数据发送到 yourPostScript.php,然后将 post 发送到外部 allow-any-origin。appspot.com 您会在 yourPostScript.php 中得到响应,并且您呼应它。

对不起,我希望这不是违法的..

--编辑--

test.php代码:

<form action="yourPostScript.php" method="GET">
<input type="text" name="card_id" value="3005">
<input type="text" name="card_id" value="">
<br>
<input type="submit" value="Submit">

yourPostScript.php 代码:(只是用于演示的片段)

   <?php 
/* validating method and fields i think is enough for ignoring images and others..*/
   if($_SERVER['REQUEST_METHOD']!='POST') die;
   if(!$_POST['card_id']) die;

    $url = 'http://vend.giftcardservices.nl/saldo/check?
    show_form=0&card_id=3005&card_id=&ajax=1';
    $data = array('card_id' => $_POST['card_id'], 'other_field' => $_POST['other_field']);

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data),
    ),
);
$context  = stream_context_create($options);
echo $result = file_get_contents($url, false, $context); ?>