iframe不显示滚动条并且设置动态高度、添加内部样式和脚本

html 复制代码
<iframe id="myIframe" frameborder="0" width="100%" scrolling="no" onload="this.height = this.contentWindow.document.body.scrollHeight+300">
</iframe>
javascript 复制代码
$('#myIframe').load(function () {
				//body{text-align:center;}
				// table{margin:0px auto;}
				$('#myIframe').contents().find("head").append($(`<style>
				ol{
					list-style:none !important;
					list-style-type:none !important;
				}
				ul{
					list-style:none !important;
					list-style-type:none !important;
				}
				table{border-top:1px solid #7F7F7F!important;border-left:1px solid #7F7F7F!important;border-collapse:collapse;}
				table td{
					border-bottom:1px solid #7F7F7F!important;border-right:1px solid #7F7F7F!important;padding:5px 12px;
					word-break:break-all !important;word-wrap:break-word !important;
					vertical-align:middle !important;text-align:center !important;
				}
				</style>`));
				$('#myIframe').contents().find("head").append($(`<link rel="stylesheet" type="text/css" href="static/Ueditor/third-party/SyntaxHighlighter/shCoreDefault.css"/>`));

				var script   = document.createElement("script");
				script.type  = "text/javascript";
				script.charset  = "utf-8";
				script.text   = `
					const pre = document.getElementsByTagName('pre');
					for(let me of pre){
						me.setAttribute("class","syntaxhighlighter");
					}
					`;
				$('#myIframe').contents().find("head").get(0).appendChild(script);

				setTimeout(function(){//一定要加延时,不然有问题
					$('#myIframe').get(0).height = $('#myIframe').get(0).contentWindow.document.body.scrollHeight+300;//多加点
				}, 100);
			});
相关推荐
计算机魔术师3 分钟前
Fable 5.1 来了,智能体任务成本降 45%——Anthropic 这次为何降价这么狠
前端
Csvn4 分钟前
现代 CSS 新特性深度:container query、:has()、@scope 与 subgrid
前端
计算机魔术师9 分钟前
Anthropic 自己承认:模型越来越难管住了
前端
两只羊ovo18 分钟前
Agent 干活的底层地基:path 路径 + fs 文件系统,一次讲透
前端
xiaominlaopodaren18 分钟前
three.js地图视口瓦片(二):如何形成完整视口多边形
javascript·gis·three.js
一用书生18 分钟前
我给 ChatGPT、DeepSeek、Kimi 都加了一个「保存为笔记」按钮
前端·ai编程·vibecoding
咖啡无伴侣21 分钟前
1. 从零搭建企业级 Monorepo 工程化模板:初始化、应用创建与共享 TypeScript 配置
前端·前端框架
moonsims21 分钟前
再议AiBrainBox-V的前左右三目布局-满足多目SLAM算法;对比单下视VIO(低空、地面纹理丰富、飞行速度适中无人机 )&多目VIO
前端·人工智能·量子计算
AI编程实验室22 分钟前
Agent Handoff 自动跟踪 Skill:安装、事件映射与证据分级
前端·ai编程
KoPa23 分钟前
HeySmart:事件总线——异步解耦的艺术
前端·后端