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

如何通过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

    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试