本地文件iframe的htmldsiplay的jupyter交叉源对象问题

2024-04-25 14:00:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我想显示一个IFrame并从IFrame访问一个对象,我需要将值从IFrame传回jupyter笔记本。你知道吗

如果我显示一个html(直接在浏览器中显示时可以工作),我会得到Permission denied to access property "ketcher" on cross-origin object,因为我的ipynp一个html文档在jupyter(文件和笔记本)中有不同的路径,即使在同一个目录中:

Location http://x250.local:3333/notebooks/sketcher/ketcher/Untitled.ipynb?kernel_name=python3
Location http://x250.local:3333/files/sketcher/ketcher/ketcher.html

如何为我的客户更改此位置IFrame.document文件或者母亲的文件,这样我就不会得到这个跨来源的错误?你知道吗

我还尝试直接使用jupyter的IFrame来显示我的html,但是在从jupyter IFrame调用的html中,没有访问IPython.notebook.kernel内核. 你知道吗

你知道我该怎么做吗?你知道吗

<html>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>
  jQuery(function ($) {
    $('#iframe').on('load', function () {
      console.log(document.location);
      console.log(this.contentWindow.location);
      var ketcher = this.contentWindow.ketcher;

    });
  });

</script>

  <body>
      <iframe id="iframe" src="ketcher.html" scrolling="no" width="800" height="600">
      </iframe>
  </body>

</html>

Tags: 文件httponlocalhtmlscript笔记本jupyter