0.0.1 • Published 6 years ago

gitbook-plugin-add-hash-to-parent v0.0.1

Weekly downloads
3
License
-
Repository
-
Last release
6 years ago

使用

当gitbook做为其它页面的子页面嵌入时,在gitbook所在的iframe内切换文章时,并不会在父页面的url中反映出来,这将导致不能复制文章的url时总是会跳到这个gitbook的首页,极为不方便。

此插件安装后,会在切换文章的时候,利用history.pushState,将当前url作为父页面的hashkey追加到父页面url的未尾,如:

gitbook页面url为:

http://localhost/xxx-gitbook/pageA.html

则其父窗口的url会显示为:

http://localhost/path/to/page.html#xxx-gitbook/pageA.html

当然,你还需要在父容器的js代码里添加处理hashkey的部分的代码,将iframe跳转到对应的页面。

比如:

$(function() {
    location.hash && $('#iframe-id').attr('src', location.hash.substring(1));
});