iframe引用父页面样式_iframe中父项的样式

news/2024/7/9 23:45:35 标签: javascript, js, css, html, vue
htmledit_views">
iframe引用父页面样式

iframe引用父页面样式

Here's a JavaScript that let's you style an iframe just like its top parent. The script is basically just a proof of concept I did after talking to a friend about similar problem he has had in the past, so feel free to modify and use if you like it.

这是一个JavaScript,可让您像对其上级父级一样对iframe进行样式设置。 脚本基本上只是概念证明,是我在与朋友谈论他过去遇到过的类似问题之后所做的,因此,可以随意修改和使用。

So I have a page, called big.html and a stylesheet for this page, called big.html" title=css>css. On the page there is an iframe that loads small.html. small.html has its own style, called small.html" title=css>css. What my little Javascript function does is:

所以我有一个网页,名为big.html并为此页面样式表,称为big.html" title=css>css 。 在页面上,有一个内嵌框架,可加载small.html 。 small.html具有自己的样式,称为small.html" title=css>css 。 我的Javascript小功能是:

  1. Getting all top parent's <link> tags

    获取所有顶级父项的<link>标签

  2. Looping through the tags and checking if the rel attribute has value stylesheet

    遍历标签并检查rel属性是否具有值stylesheet

  3. For all stylesheets found, makes a copy of the link tag and all its attributes and adds it to the head of the iframed page

    对于找到的所有样式表,请复制链接标记及其所有属性,并将其添加到iframed页面的开头

Here's the code:

这是代码:

function styleMe() {
  if(window.top && window.top.location.href != document.location.href) {
  // I'm small but I'm not alone
 
    // all parent's <link>s
    var linkrels = window.top.document.getElementsByTagName('link');
    // my head
    var small_head = document.getElementsByTagName('head').item(0);
    // loop through parent's links
    for (var i = 0, max = linkrels.length; i < max; i++) {
      // are they stylesheets
      if (linkrels[i].rel && linkrels[i].rel == 'stylesheet') {
         // create new element and copy all attributes
        var thestyle = document.createElement('link');
        var attrib = linkrels[i].attributes;
        for (var j = 0, attribmax = attrib.length; j < attribmax; j++) {
          thestyle.setAttribute(attrib[j].nodeName, attrib[j].nodeValue);
        }

         // add the newly created element to the head
        small_head.appendChild(thestyle);
 
      }
    }
 
    // maybe, only maybe, here we should remove the kid's own styles...
 
  } else {
    alert('I hate to tell you that, but you are an orphant :( ');
  }
}

To see the code in action, see big.html.

要查看实际的代码,请参阅big.html

Tell your friends about this post on Facebook and Twitter

在Facebook和Twitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/parents-styles-in-an-iframe/

iframe引用父页面样式


http://www.niftyadmin.cn/n/1306780.html

相关文章

php mysql 读取表结构_PHP mysqli获取数据表以及表结构

$mysqli new mysqli(‘localhost‘,‘root‘,‘‘,‘le‘);$result $mysqli->query(‘SHOW TABLES‘);//执行查询语句//输出此数据库中表结构$tables array();while($arr $result->fetch_assoc()){//编辑查询结果$tables[] $arr;}echo ‘‘;//通过字段名获取数据表结…

linux 查找mysql服务器_linux下查看mysql服务器

{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":6,"count":6}]},"card":[{"des":"云服务器 ECS(Elastic Compute Service)是一…

SQL注入攻击三部曲之进阶篇

SQL注入攻击三部曲之进阶篇 通过入门篇的学习&#xff0c;我们知道了SQL注入攻击的判断方法&#xff0c;但是如果想侵入网站&#xff0c;获取网站的机密内容&#xff0c;那么仅靠入门篇的知识是无法达到的。本篇文章我们将进一步的分析SQL注入攻击。 首先&#xff0c;我们先看看…

mysql mgr搭建_MGR的搭建部署

1. MGR介绍MySQL Group Replication(下简称&#xff1a;MGR)是MySQL官方推出的一种基于Paxos协议的状态机复制。在MGR出现之前&#xff0c;用户常见的MySQL高可用方式&#xff0c;无论怎么变化架构&#xff0c;本质就是Master-Slave架构。MySQL 5.7版本开始支持无损半同步复制(…

磁力

突如其来对磁力有了很大的兴趣。磁力是什么&#xff1f;力和力之间的相互作用必须以物质为媒介那么磁力之间的作用物质是什么&#xff1f;为什么这些物质只对具有磁性的物质有作用&#xff1f;以前的知识说是场的作用&#xff0c;有磁场和电场&#xff0c;但是场的存在形式究竟…

SQL注入攻击三部曲之高级篇

SQL注入攻击三部曲之高级篇 经过了入门篇和进阶篇的学习&#xff0c;相信诸位想要破解一般的网站是没有什么问题了&#xff0c;但是先别得意。正所谓学海无涯&#xff0c;技术的进步也是没有止境的。SQL注入是一个看起来简单&#xff0c;但是变数很多的过程。接下来的高级篇让我…

python的基础学习学习第一章

都是整数时相除会取整&#xff0c;但只要有一个是分数&#xff08;5.0也可以&#xff09;&#xff0c;结果自然是浮点型的 幂运算符是**&#xff0c;即2**3&#xff0c;结果会等于8&#xff0c;另一种表达pow&#xff0c;即pow(2,3)的出来的结果是8 大于2147483647的数为长整…

python基础学习第二章之数据结构

前言&#xff1a;什么是数据结构 通过某种方式组织在一起的数据元素的集合 python中最基本的数据结构是序列&#xff0c;序列中每一个数据元素被分配一个位置&#xff0c;该位置称为索引。第一个索引是0. python有6中内建序列&#xff0c;分别为扩列表&#xff0c;元组&…