【发布时间】:2011-02-07 22:23:58
【问题描述】:
我如何从 iframe 中获取 json,它不是 jsonp,这是我所拥有的。 (当然只使用 javascript)
<script type="text/javascript">
var theFrame = document.getElementById('iframe');
var theWin = theFrame.contentWindow;
var theDoc = theFrame.contentDocument || theFrame.contentWindow.document;
var json = theDoc;
var msgs = JSON.parse(theDoc);
for (var i = 0, l = msgs.length; i < l; i++) {
var msg = msgs[i];
var div = document.createElement('div');
div.innerHTML = 'Hello ' + msg.user + ' your Id is: ' + msg.ID + 'and your message is: ' + msg.message + ' it has ' + msg.replies + ' replies';
document.body.appendChild(div);
</script>
<iframe id="iframe" name="iframe" src="http://jsonsource.com/not/jsonp/" width="100" height="100">
<p>Your browser does not support iframes.</p>
</iframe>
【问题讨论】:
标签: javascript html json iframe