首页 > 解决方案 > 将 iframe 文本传递给 laravel 控制器

问题描述

我遇到了问题...我的 iframe 基本上是一个输入框(下图),我想从用户那里获取输入到我的控制器我可以接受它传递文本的 html,这就是我期待,因为它不是一个普通的文本框,我不能只将它传递给 laravel,因为它运行 java 代码。有什么建议吗?

我的页面:

@extends('layouts.app')

@section('content')
    <div class="content">
        <div class="d-flex justify-content-center mt-sm-3">
            <h3>Insert text</h3>
        </div>
        <div class="d-flex justify-content-center mt-xl-1">
            <form method="POST" action="{{ route('test.create') }}">
                @csrf
                <iframe src="http://localhost:8080/test" width="560" height="650"></iframe>

                <button type="submit" class="btn btn-outline-success w-100 mb-3">
                    Done
                </button>
            </form>
        </div>

    </div>

@endsection

图片(仅限 iframe 和按钮): 文本

标签: phplaraveliframe

解决方案


我制作了这段代码,它在我身上运行良好。看看:

ex1.html

<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <title>Page Title</title>
 <meta name="viewport" content="width=device-width, initial-scale=1">

</head>
<body>
    <form>
        <input type="text" id="sachin"/>
    </form>
</body>
</html>

ex.html

<body>
  <iframe src="ex1.html" id="iframeId" style="height:380px;width:100%"></iframe>
 <script>
  $(function(){
    var iframe = document.getElementById("iframeId");
    $(iframe).on('load',function(){
      var innerDoc = (iframe.contentDocument) 
           ? iframe.contentDocument 
           : iframe.contentWindow.document;
      var input= $(innerDoc).find('#sachin');
      $(input).on('keyup', function(){
          //do anything with the value
          console.log($(this).val());
      });

    });
  });
  </script>
</body>

希望这可以帮助。


推荐阅读