简体   繁体   English

iFrame 大小随内容动态变化

[英]iFrame size to change dynamically with content

What I am trying to do with that javascript is iFrame a chat widget which I am hosting on a webpage - it is initially a launcher, a small round clickable icon, Which then launches to a full sized window.我试图用那个 javascript 做的是 iFrame 一个我在网页上托管的聊天小部件 - 它最初是一个启动器,一个小的圆形可点击图标,然后启动到一个全尺寸的窗口。 As it is, my iFrame code simply captures the entire page and shows that At a certain height and width on this external site.实际上,我的 iFrame 代码只是捕获了整个页面,并在此外部站点上以特定高度和宽度显示。 The problem I have is the iFrame is the entire page, so especially when it is just The small clickable launcher, the iFrame is taking up a massive chunk of this external site which obviously isn't practical as its Unsightly and you can't click on content beneath it!我遇到的问题是 iFrame 是整个页面,所以特别是当它只是可点击的小型启动器时,iFrame 占用了这个外部站点的很大一部分,这显然不实用,因为它不美观而且你不能点击在它下面的内容! And then even with the chat widget expanded its still not okay,然后即使扩展了聊天小部件,它仍然不行,

What I want to do is somehow iFrame just the chat-launcher at first, and then the window when the widget is expanded..我想要做的是以某种方式 iFrame 首先只是聊天启动器,然后是小部件展开时的窗口..

How did I think to do it - maybe have the iFrame expand depending on the content - I have no clue on this.我是怎么想的 - 也许 iFrame 会根据内容展开 - 我对此一无所知。 I also thought - Could I make the chat launcher the entire size of the page, just iframe that, then when its clicked, id obviously still Need the iframe on the clients page to expand with the content, or perhaps that is the solution for an expanding iFrame?我还想 - 我可以让聊天启动器成为页面的整个大小,只是 iframe,然后当它被点击时,id 显然仍然需要客户端页面上的 iframe 来扩展内容,或者这可能是一个解决方案扩展 iFrame?

My javascript code I am using:我正在使用的 javascript 代码:

prepareFrame();

function prepareFrame() {
    console.log("yes this consoles inside of prepareFrame")
    var ifrm = document.createElement("iframe");
    ifrm.setAttribute("src", "https://fb23e954.ngrok.io");
    ifrm.style.width = "640px";
    ifrm.style.height = "480px";
    ifrm.style.position="fixed";
    ifrm.style.right="0";
    ifrm.style.bottom="0";

    document.body.appendChild(ifrm);
}

It would be amazing if anybody could help at all, thanks if you can!如果有人能提供帮助,那就太棒了,如果可以的话,谢谢!

Why don't you just use Viewport Width and Viewport Height instead of px?为什么不直接使用视口宽度和视口高度而不是 px?

function prepareFrame() {
    console.log("yes this consoles inside of prepareFrame")
    var ifrm = document.createElement("iframe");
    ifrm.setAttribute("src", "https://fb23e954.ngrok.io");
    ifrm.style.width = "80vw";
    ifrm.style.height = "60vh";
    ifrm.style.position="fixed";
    ifrm.style.right="0";
    ifrm.style.bottom="0";

    document.body.appendChild(ifrm);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM