其他分享
首页 > 其他分享> > pdf.js 标题修改

pdf.js 标题修改

作者:互联网

打开viewer.js 搜索 setTitleUsingUrl

setTitleUsingUrl(url = "") {
    this.url = url;
    this.baseUrl = url.split("#")[0];
    let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");

    if (!title) {
      try {
        title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
      } catch (ex) {
        title = url;
      }
    }

    this.setTitle(title);
  },

  setTitle(title) {
    if (this.isViewerEmbedded) {
      return;
    }
    // 修改标题
    // document.title = title;
    const ts = title.split("\\");
    document.title = ts[ts.length - 1];
  }

我这里直接修改了 setTitle 方法

显示的名字太长了,所以我这理就显示最后一个\ 后面的内容

标签:pdfjsLib,title,url,setTitleUsingUrl,setTitle,ts,标题,pdf,js
来源: https://www.cnblogs.com/rchao/p/14902854.html