简体   繁体   English

重新加载 iFrame CSS

[英]Reload iFrame CSS

I'm developing a system, which supports CSS themes.我正在开发一个支持 CSS 主题的系统。 It's Ok so far, I can change the theme as desired, but the system is composed by two parts:到目前为止还可以,我可以根据需要更改主题,但系统由两部分组成:

First is the "skeleton" of the system: it contains the menu and the options to change theme.首先是系统的“骨架”:它包含菜单和更改主题的选项。 That menu loads the contents of the second part which is composed essentially by an iframe which loads the modules called by the clicks on menu.该菜单加载第二部分的内容,该部分主要由 iframe 组成,该 iframe 加载通过点击菜单调用的模块。

I can change the theme of the first part of the system using the following code:我可以使用以下代码更改系统第一部分的主题:

$("link").attr("href", "css/temas/"+theme_name+".css");

The theme_name is gathered by reading the link on the menu click. theme_name 是通过阅读菜单单击上的链接来收集的。 The system is ok here, and no change is needed.系统在这里没问题,不需要更改。 Beyond changing the main theme, it records a cookie, which is used to read for further system theming.除了更改主题之外,它还会记录一个 cookie,用于读取进一步的系统主题。

So, the second part of the system also reads that cookie to apply the theme, but it doesn't change instantly as the main part does!因此,系统的第二部分也读取该 cookie 以应用主题,但它不会像主要部分那样立即更改!

For example, when I click the theme icon, it instantly applies the theme without refreshing the screen, but that doesn't happens to the second part!例如,当我单击主题图标时,它会立即应用主题而不刷新屏幕,但第二部分不会发生这种情况! It apply the theme, but it's shown only if I reload the iframe, and reloading, ain't cool!它应用了主题,但只有在我重新加载 iframe 时才会显示,然后重新加载,一点都不酷!

I'm trying to change the iframe theme with the following code:我正在尝试使用以下代码更改 iframe 主题:

$("#ifr_main link").attr("href", theme_name);

Where #ifr_main is the iframe name!其中#ifr_main 是 iframe 名称!

Does anybody knows how can I figure that out and apply the new CSS without having to refresh the page, as I do on the menu?有谁知道如何解决这个问题并应用新的 CSS,而不必像在菜单上那样刷新页面?

You need to select the content of the iFrame first before trying to select it's link element.在尝试选择它的链接元素之前,您需要先选择 iFrame 的内容。

$("#ifr_main").contents().find("link").attr("href", theme_name);

Side note, iFrames can be ugly :)旁注,iFrame 可能很丑 :)

It is because iframe content was loaded when your page is loaded, so after it, you cannot change its looking unless you are using JQuery/ajax methods or reload.这是因为 iframe 内容是在您的页面加载时加载的,所以在它之后,除非您使用 JQuery/ajax 方法或重新加载,否则您无法更改其外观。
Yo can find some questions about it你可以找到一些关于它的问题
here , here and here 这里这里这里

maybe you can reload your ifreame via ajax, read here也许您可以通过 ajax 重新加载您的 ifreame,请阅读 此处
Finally you should watch this video for more unique way.最后,您应该以更独特的方式观看此视频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM