我有兩個頁面,一個在另一個頁面的iframe中運行:test.php在check.php中運行。 Test.php是作爲代理來發揮作用以避開交叉來源。 iframe正常工作並提供正確的值。但是,當我嘗試從父頁面中的div ID獲取值時,我得到以下響應: 未捕獲的SecurityError:阻止了源於「http://localhost」的框架訪問源於「http://www.allow-any-origin.appspot.com」的框架。協議,域和端口必須匹配。從iframe獲取div值
這裏是我的代碼:
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">
我以爲這條路是讓瀏覽器接受這種方式。任何人都可以看到我要去哪裏嗎?
如果該網站正在設置CORS,請使用Ajax。如果不在您的域上創建代理來獲取它。 – epascarello
這就是我認爲我這樣做的原因。 – user3069332