New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@skit/doctitle

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@skit/doctitle

An easy way to dynamically change the document title, compatible with SPA in iOS/Safari, and support fixed prefixes and suffixes. 一种动态修改文档标题的简便方式,兼容 iOS/Safari 中的 SPA,支持固定前缀、后缀。

latest
Source
npmnpm
Version
1.0.0-rc
Version published
Maintainers
1
Created
Source

@skit/doctitle

特性

  • 动态设置 document.title

  • 可配置固定的前缀、后缀;

  • 兼容 iOS/MacOS 系统下的 SPA 应用,解决 SPA 动态设置文档标题无效的问题;

  • 支持 TypeScript。

用法

安装:

npm install @skit/doctitle

导入:

// require 方式
const $$title = require('@skit/doctitle');

// import 方式
import $$title from '@skit/doctitle';

基本用法:

// 设置标题,设置后文档标题为 'This is a Title'。
$$title.setTitle('This is a Title');

// 设置前缀,设置后文档标题为 'PREFIX - This is a Title'。
$$title.setPrefix('PREFIX - ');

// 设置后缀,设置后文档标题为 'PREFIX - This is a Title | SUFFIX'。
$$title.setSuffix(' | SUFFIX');

高级技巧:

// 兼容 iOS/MacOS 的原理是在页面中创建一个隐藏的 iframe,并设置其 src 属性。
// 默认的加载路径是 ‘/favicon.ico’。
// 如果你的网站不支持这个路径,那么可以指定为其他的路径。
$$title.withHackSource('http://example.com/hack.txt');

// 还可以清空前缀和后缀,直接修改文档标题。
$$title.setTitle('This is a Title', { flush: true });

Keywords

document title

FAQs

Package last updated on 27 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts