drne47241 2016-10-11 20:28
浏览 554

如何通过javascript在iframe上自动填充数据

Hello I want to autofill data in iframe on cross domain.I have a code but it's not working. please help me.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
function autoFill() {
var f=fm.document.forms[0];
f.form-control.value='Zanne';
f.submit();
}
</script>

</head>
<body>
<div>
<button type="button" onclick="autoFill();">autoFill</button>
</div>
<iframe name="fm" id="fm" src="url.com" width="100&#37;" height="100%"></iframe>
</body>
</html>

the input filled:

Have any way to do this.

  • 写回答

1条回答 默认 最新

  • douyi9705 2016-10-11 20:31
    关注

    This is going to be a CORS violation.

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

    There are some workarounds to this. You have to use the postMessage API. Your parent window would need to send JavaScript events to the iFrame, which would need to have an event listener and react to it.

    https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

    评论

报告相同问题?

悬赏问题

  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao