【问题标题】:Opening XPages from launch settings break my stylesheet references从启动设置中打开 XPage 会破坏我的样式表引用
【发布时间】:2014-12-18 07:28:41
【问题描述】:

我注意到,如果地址栏中的路径指向 nsf 而不是 xsp,则有时来自样式表中的 url 的相对链接不起作用

所以如果我在面板中有以下内联样式

background-image:url('footer-bg.png')

我使用 acme.com/mypage.nsf 访问我的网站(启动属性设置为 start.xsp) 背景未加载

但如果我使用 xsp 的完整路径,背景工作正常,例如 acme.com/mypage.nsf/start.xsp

如何解决这个问题,以便我的内联样式表背景始终有效

【问题讨论】:

    标签: css redirect styles xpages relative-path


    【解决方案1】:

    如果您在数据库属性中自动启动 XPage,诀窍是始终添加尾部斜杠。

    var h=window.location.href;
    if(h.indexOf(".xsp")==-1){
      if(h.substring(h.length,h.length-1)!="/"){
         window.location.href+="/"
    }}
    

    我在这里写了一篇关于它的博客文章 http://www.xpagedeveloper.com/2013/quicktip-get-right-path-when-autolaunching-an-xpage

    或者使用 Thomas 添加的这个 jQuery 代码

     $(function(){
     var h=window.location.href;
    if(h.indexOf(".xsp")==-1){
    if(h.substring(h.length,h.length-1,1)!="/"){
     window.location.href+="/"
    }}
    })
    

    【讨论】:

      【解决方案2】:

      我有一个 sn-p,它驻留在我在每个页面上使用的布局 CC 中:http://snippets.notesx.net/Privat/osnippets.nsf/snippet.xsp?documentId=13EBFA7FDDC4354EC1257C120005018E

      在 beforePageLoad 中你输入以下代码:

      var url = facesContext.getExternalContext().getRequest().getRequestURI();
      if(url.indexOf(".xsp")==-1){
          if(url.endsWith("/")){
              url = url.substr(0, url.length-1)
          }
          context.redirectToPage(url+view.getPageName())
      }
      

      【讨论】:

        猜你喜欢
        • 2022-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-04
        • 1970-01-01
        • 1970-01-01
        • 2013-12-12
        相关资源
        最近更新 更多