简体   繁体   English

有没有办法只为页面的特定部分(即标题)加载外部样式表并为所有其他部分“卸载”该样式表?

[英]Is there a way to load an external stylesheet only for a specific part of the page (i.e. the header) and "unload" that stylesheet for all other parts?

I am trying to integrate a help center (from Zendesk) seamlessly.我正在尝试无缝集成帮助中心(来自 Zendesk)。 For that I have copied the Header and the Footer of our mainpage into the help center page.为此,我已将主页的 Header 和页脚复制到帮助中心页面。 I apply the CSS of the external page in the header with this:我将外部页面的 CSS 应用到 header 中:

<link href=".../web/cache/Test.css" media="all" rel="stylesheet" type="text/css" />

The problem is that using that it will apply the stylesheet to the entire page and mess up all the other articles and content.问题是使用它会将样式表应用到整个页面并弄乱所有其他文章和内容。

I need a way to apply the stylesheet only to a specific part of the page(the header).我需要一种方法将样式表仅应用于页面的特定部分(标题)。 Another note is that the stylesheet is huge, and I cannot edit it in any way(eg editing the selectors to only apply to the header class)另一个注意事项是样式表很大,我无法以任何方式对其进行编辑(例如,将选择器编辑为仅适用于 header 类)

I tried searching for solutions but only came up with 8 year old posts about using something like <style scoped> , though that also seemed outdated.我尝试寻找解决方案,但只找到了 8 年前关于使用<style scoped>类的帖子,尽管这似乎也已过时。

I also tried using this javascript function I found, to no avail:我也尝试使用我发现的这个 javascript function,但无济于事:

function applyCSSFileToElement(cssUrl, elementSelector, callbackSuccess, callbackError) {
    callbackSuccess = callbackSuccess || function(){};
    callbackError = callbackError || function(){};
    $.ajax({
        url: cssUrl,
        dataType: "text/css",
        success: function(data) {
            applyCSSToElement(data, elementSelector);
            callbackSuccess();
        },
        error: function(jqXHR) {
            callbackError();
        }
    })
}

How about this?这个怎么样?

  • store the relevant code you need INSIDE Zendesk Help Center code area将您需要的相关代码存储在 Zendesk 帮助中心代码区域中
  • check with Java or Jquery the relavent conditions查询Java或Jquery相关条件
  • is the element of the page present AND is the URL of the page the one you want to have your script executed是当前页面的元素并且是页面的 URL 是您要执行脚本的页面
  • if the above is true如果以上为真
  • execute your code via Jquery通过 Jquery 执行您的代码

暂无
暂无

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

相关问题 使用外部CSS样式表仅更改HTML的特定部分 - Alter with an external CSS Stylesheet only a specific part of the HTML 链接到外部样式表时不会加载页面 - Page will not load when linking to external stylesheet 将外部样式表链接到特定的 HTML 元素 - Linking an external stylesheet to only specific HTML elements 如何在Play中仅将一页使用特定样式表 - How to use a specific stylesheet for only 1 page in Play 从 CSS 样式表中排除标题的一部分? - Exclude one part of header from CSS stylesheet? 有没有一种方法可以根据其他页面的样式表来更改页面的样式表? - Is there a way of changing a page's stylesheet based on the stylesheet of a different page? 将外部页面加载到DIV中,并将外部页面的样式表的效果限制在该DIV中 - Load external page into a DIV, and confine the effects of the external page's stylesheet to that DIV 有没有一种方法可以在 css 的外部样式表中轻松识别选择器,而无需逐行查看所有代码? 在 html css - Is there a way I can easily identify a selector in external stylesheet in css without going through all the code line by line? in html css 将外部样式表分配给html中的特定表 - Assigning external stylesheet to specific table in html 为什么将我的样式表加载到除一页之外的所有其他页面上,我在该页面上获取样式表文件的404 - why my style sheets are loaded for all other pages except one page, i get 404 for stylesheet files on that page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM