ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

[MCP-UI] Dynamic Sizing

[MCP-UI] Dynamic Sizing

Users expect iframes to fit their content perfectly, not waste space or require scrolling. The journal viewer should automatically adjust to show exactly what's needed.

const height = document.documentElement.clientHeight
const width = document.documentElement.clientWidthwindow.parent.postMessage({type: 'ui-size-change',payload: { height, width },},'*',
)
Use clientHeight and clientWidth to measure the full content dimensions, then send a ui-size-change message to the parent window so it can resize the iframe accordingly.
The static preferred-frame-size from the previous exercise works for fixed layouts, but journal entries have varying content lengths. A short entry wastes space, while a long entry gets cut off.
 
 
返回列表