A 框架将 websubsurface 源设置为变量

发布于 2025-01-09 05:52:06 字数 1906 浏览 0 评论 0原文

我正在使用 websurface A 框架组件 (),我想知道如何才能做到这一点,以便当单击按钮时,websurface 的 url 将更改为我定义的名为 source 的变量的值。例如,如果变量源设置为“https://google.ca”并且您单击按钮,则 websurface url 将更改为 https://google.ca。当前代码:

 <!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Example 1</title>
    <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/aframe-websurfaces.umd.js"></script>
    <script>
    function updateSource() {
    let source = "https://google.ca";
    
    }
    </script>
  </head>
  <body>
  <button style="position: fixed; z-index: 100000;" onclick="updateSource()">
  update src
  </button>
    <a-scene>
      <!--Camera-->
      <a-entity
        wasd-controls="acceleration: 20;"
        camera="active: true"
        look-controls="pointerLockEnabled: false"
        position="0 1.6 0"
      >
        <a-cursor position="0 0 -.05" scale=".04 .04 1"></a-cursor>
      </a-entity>

      <!--Environment-->
      <a-sky color="#aff"></a-sky>
      <a-plane
        rotation="-90 0 0"
        width="20"
        height="20"
        color="#3fa841"
      ></a-plane>

      <!--Websurface-->
      <a-entity
        websurface="url:https://aframe.io/; width:4; height:2;"
        position="2.25 1.5 -4"
      ></a-entity>

    </a-scene>
  </body>
</html>

摆弄代码: https://jsfiddle.net/AidanYoung/7vye3osa/2/

I am using the websurface A-frame component () and I'm wondering how I can make it so when a button is clicked, the url of the websurface will change to the value of a variable I've defined called source. What should happen is for example, if the variable source is set to "https://google.ca" and you click the button, the websurface url will change to https://google.ca. Current code:

 <!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Example 1</title>
    <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/aframe-websurfaces.umd.js"></script>
    <script>
    function updateSource() {
    let source = "https://google.ca";
    
    }
    </script>
  </head>
  <body>
  <button style="position: fixed; z-index: 100000;" onclick="updateSource()">
  update src
  </button>
    <a-scene>
      <!--Camera-->
      <a-entity
        wasd-controls="acceleration: 20;"
        camera="active: true"
        look-controls="pointerLockEnabled: false"
        position="0 1.6 0"
      >
        <a-cursor position="0 0 -.05" scale=".04 .04 1"></a-cursor>
      </a-entity>

      <!--Environment-->
      <a-sky color="#aff"></a-sky>
      <a-plane
        rotation="-90 0 0"
        width="20"
        height="20"
        color="#3fa841"
      ></a-plane>

      <!--Websurface-->
      <a-entity
        websurface="url:https://aframe.io/; width:4; height:2;"
        position="2.25 1.5 -4"
      ></a-entity>

    </a-scene>
  </body>
</html>

Fiddle with code: https://jsfiddle.net/AidanYoung/7vye3osa/2/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

场罚期间 2025-01-16 05:52:07

该组件使用 i-frame 可通过引用访问< /a>:

element.websurface_iframe

您可以像任何其他 i-frame 一样使用它 - 就像更改 src 属性一样:

<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-websurfaces.umd.js"></script>
<script>
  function updateSource() {
    let source = "https://threejs.org";
    const websurfaceEl = document.querySelector("[websurface]")
    websurfaceEl.websurface_iframe.src = source
  }
</script>
<button style="position: fixed; z-index: 100000;" onclick="updateSource()">
update src
</button>
<a-scene>
  <a-entity websurface="url:https://aframe.io/; width:4; height:2;" 
            position="0 1.6 -2"></a-entity>
</a-scene>


请记住 - 原始服务器可能不欢迎来自其他来源的请求 - 例如 https://google.ca 它明确告诉您,只有来自同一来源的网站可以在框架中显示它(检查下面代码片段中的日志):

X-Frame-Options' to 'sameorigin'

<div>
  <iframe src="https://google.ca" width="500" height="250">
</div>

The component is using an i-frame accessible with the reference:

element.websurface_iframe

You can use it like any other i-frame - like changing the src property:

<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-websurfaces.umd.js"></script>
<script>
  function updateSource() {
    let source = "https://threejs.org";
    const websurfaceEl = document.querySelector("[websurface]")
    websurfaceEl.websurface_iframe.src = source
  }
</script>
<button style="position: fixed; z-index: 100000;" onclick="updateSource()">
update src
</button>
<a-scene>
  <a-entity websurface="url:https://aframe.io/; width:4; height:2;" 
            position="0 1.6 -2"></a-entity>
</a-scene>


Keep in mind - the originating server may not welcome requests from other origins - like https://google.ca which explicitly tells you, that only websites from the same origin may display it in a frame (check the logs in the snippet below):

X-Frame-Options' to 'sameorigin'

<div>
  <iframe src="https://google.ca" width="500" height="250">
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文