gpt4 book ai didi

javascript - 脚本添加 iframe 内容在 chrome 中没有用户代理样式

转载 作者:太空宇宙 更新时间:2023-11-04 08:34:39 25 4
gpt4 key购买 nike

Chrome 版本:58

通常,表单会有一个用户代理样式margin-bottom: 1em;

<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta charset="utf-8" />
</head>

<body>
<form action="#">
First name:<br><input type="text" name="firstname" value="Mickey"><br>
Last name:<br><input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit"></form>
<div>hello world</div>
</body>

</html>

with user agent style

但是当我通过脚本向 iframe 添加内容时,表单没有样式 margin-bottom: 1em;

    <!DOCTYPE html>
<html>
<head>
<title>clack test</title>
<meta charset="utf-8" />
</head>
<body>
<script>
var iframe = document.createElement("iframe");
iframe.id = 'iframe';
iframe.width = '100%';
iframe.height = '886';
iframe.setAttribute("scrolling", "no");
iframe.setAttribute("frameborder", "0");
document.body.appendChild(iframe);

// find the iframe's document and write some content
var idocument = iframe.contentDocument;
idocument.open();
idocument.write("<!DOCTYPE html>");
idocument.write("<html>");
idocument.write("<head></head>");
idocument.write('<body><form action="/demo/demo_form.asp\">First name:<br><input type="text" name="firstname" value="Mickey"><br>Last name:<br><input type="text" name="lastname" value="Mouse"><br><br><input type="submit" value="Submit"></form><div>hello world</div></body>');
idocument.write("</html>");
idocument.close();
</script>
</body>
</html>

without user agent style

我想知道如何让用户代理样式在 iframe 中工作。谢谢

最佳答案

script = document.getElementById("js");
iframe = document.createElement("iframe");
document.body.appendChild(iframe);
iframe.appendChild(script);
<script id="js">
// the script you want to inject
alert("Injected");
console.log("Injected");
</script>

尝试使用这样的东西

HTML:

<script id="js">
// the script you want to inject
</script>

JS:

script = document.getElementById("js");
iframe.appendChild(script);

我做了一个WeaveLiveWeave .

关于javascript - 脚本添加 iframe 内容在 chrome 中没有用户代理样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44565378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com