控制文本在 iframe(同一域)中的对齐和浮动

control text align and float in iframe (same domain)

本文关键字:对齐 文本 iframe 控制      更新时间:2023-09-26

我有一个宽度和文本的 iframe,我想在 iframe 的右侧对齐这些文本。Iframe 的 src 位于同一域中。是否可以使用 JavaScript,如果是,如何?

您可以为 iframe 中显示的页面调用 create 一个 javascript 函数来设置文本的位置。 然后,您可以从 iframe 外部调用该函数

document.getElementById('myiframe').contentWindow.setTextToRightHandSide();

HTML内部可以看起来像这样

<html>
<head>
    <title>inside html</title>
    <script>
        function setTextToRightHandSide() {
            var div = document.getElementById('textBlock');
            div.style.position = "absolute";
            div.style.right = "0px";
        }
    </script>
</head>
<body>
    <div id="textBlock">some text here</div>
</body>
</html>