gpt4 book ai didi

javascript - 覆盖 iframe 内容 css

转载 作者:太空宇宙 更新时间:2023-11-03 19:28:26 25 4
gpt4 key购买 nike

我的网站中嵌入了另一个网站的 iframe,如下所示:

    <iframe src="https://youcanbook.me/?noframe=true&skipHeaderFooter=true" id="ycbmiframe" style="width:100%;height:1000px;border:0px;background-color:transparent;" frameborder="0" allowtransparency="true"></iframe>
<script>
window.addEventListener && window.addEventListener("message", function(event) {
if (event.origin === "https://youcanbook.me") {
document.getElementById("ycbmiframe").style.height = event.data + "px";
}
}, false);
</script>

有没有办法覆盖 CSS?

谢谢

最佳答案

使用 jquery 更新 iframe 内容

Note: Contact.html file must a class with name ".yourclass", both in css file and html file or you can class name as you need at all places html,css and script.

<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>
iframe {
border-top: #c00 1px dotted;
border-right: #c00 2px dotted;
border-left: #009bdf 2px dotted;
border-bottom: #255625 4px dotted;
}

</style>
</head>
<body>
<iframe id="iframe" src="/contact.html" height="800" width="800">
</iframe>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('iframe').load(function () {
$('iframe').contents().find("head")
.append($("<style type='text/css'> .yourclass{color:#ff0000;} </style>"));
});
});
</script>
</body>
</html>

关于javascript - 覆盖 iframe 内容 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42481105/

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