动态将样式表插入IFRAME [英] Dynamically inserting stylesheet into IFRAME

查看:83
本文介绍了动态将样式表插入IFRAME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经执行以下操作:

<iframe id="portal" src="page-on-my-domain.php"></iframe>

$(document).ready(function() {

    $('#portal').load(function(){
        $('#portal').contents().find('head').append('<link href="/css/iframe.css" rel="stylesheet" type="text/css" />');
    });

});

这工作正常,但是问题是每当我更新样式表时,更新的样式都不会应用到IFRAME中.我已经尝试过重新加载页面和iframe,但是它仍在使用旧样式.

This is working fine, however the problem is whenever I update the stylesheet, the updated styles are not being applied in the IFRAME. I have tried reloading the page and the iframe but it is still picking up the old styles.

推荐答案

可能是浏览器缓存吗?在网址上附加时间戳会有所帮助:

Could it be the browser cache? Appending a timestamp to the URL could help:

$(document).ready(function() {
  $('#portal').load(function(){
    var timestamp =  +(new Date());
    $('#portal').contents().find('head').append('<link href="/css/iframe.css?'+ timestamp +'" rel="stylesheet" type="text/css" />');
  });
});

这篇关于动态将样式表插入IFRAME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆