不同域的iframe中无法使用“pseudoclass:active”。
创始人
2025-01-09 23:00:51
0

此问题的解决方法是在子域中添加一段 JavaScript 代码来处理此问题。假设您的 iframe 具有 ID“my-iframe”,以下是解决方法的代码示例:

var myIframe = document.getElementById('my-iframe');
if (myIframe) {
  // Add event listener for when the iframe is loaded
  myIframe.addEventListener('load', function() {
    // Get the iFrame's document object
    var iFrameDoc = myIframe.contentDocument;
    if (iFrameDoc) {
      // Add event listener for when the iframe's document is clicked
      iFrameDoc.addEventListener('click', function() {
        // Set the active state on the parent window
        document.body.classList.add('active');
        // Remove the active state after a short delay (to allow the user to see the active state)
        setTimeout(function() {
          document.body.classList.remove('active');
        }, 200);
      });
    }
  });
}

此代码添加了一个事件监听器,当 iframe 加载时启动。通过监听 click 事件,它将在主窗口中添加一个名为“active”的类来模拟 :active 伪类的行为。这使您可以使用 CSS 来更改子域中 iframe 的样式,就像在同一域中一样。

相关内容

热门资讯

透视软件!红龙poker透视工... 相信很多朋友都在电脑上玩过红龙poker透视工具吧,但是很多朋友都在抱怨用电脑玩起来不方便。为此小编...
透视数据!wpk辅助软件,德普... 透视数据!wpk辅助软件,德普之星辅助器,透明挂教程(素来是有挂)关于德普之星辅助器的基本介绍、功能...
透视苹果版!德普之星透视辅助软... 透视苹果版!德普之星透视辅助软件,wepoker可以透视码,可靠教程(都是存在有挂);玩家必备必赢加...
透视总结!hhpoker透视脚... 透视总结!hhpoker透视脚本下载,wepoker游戏下载,必胜教程(原来真的有挂);支持2-10...
透视辅助!wepoker底牌透... 透视辅助!wepoker底牌透视脚本怎样安装,wepoker透视底牌,AA德州教程(本来是真的有挂)...
透视挂透视!aapoker辅助... 【福星临门,好运相随】;透视挂透视!aapoker辅助插件工具,wepoker轻量版透视系统,总结教...
透视软件!aapoker辅助插... 透视软件!aapoker辅助插件工具,wepoker有透视吗,微扑克教程(真是有挂)是由北京得aap...
透视模拟器!aapkoer德州... 透视模拟器!aapkoer德州辅助挂下载,wepoker透视版下载,解说技巧(原本是真的有挂)是一款...
透视能赢!aapoker可以开... 透视能赢!aapoker可以开挂吗,wepoker轻量版书签,科技教程(原先真的有挂)准备好在aap...
透视计算!德普之星透视辅助io... 相信很多朋友都在电脑上玩过德普之星透视辅助ios吧,但是很多朋友都在抱怨用电脑玩起来不方便。为此小编...