open link inside a ‘details’ element

‘Details’ html tag is a very easy way to collapse/expand a web content: you can see it in the following example. This is the code:

<details>
<summary>expansible title</summary>
<p>all the content you want: text, images, video, in a nutshell: all possible content</p>
</details>

and this is the result:

expansible title

all the content you want: text, images, video, in a nutshell: all possible content

But there is a problem: the collapsed content is not reachable unless you click over his ‘summary’ (in the example above: ‘expansible title’) . Therefore a link from outside the details content toward some element inside that, doesn’t work, because it cannot open it.

To fix this problem you can use a little javascript:

  const openDetailsIfAnchorHidden = evt => {
  const targetDIV = document.querySelector(evt.target.getAttribute("href"));
  if ( !! targetDIV.offsetHeight || targetDIV.getClientRects().length ) return;
  targetDIV.closest("details").open = true;
 }

 [...document.querySelectorAll("[href^='#']")].forEach( 
   el => el.addEventListener("click", openDetailsIfAnchorHidden )
 );

to be put at the bottom of a page (otherwise it doesn’t work).

link from outside to a part of a file

pdf

It is possible to link a page of a pdf, with the following syntax:

file:///your-path-here/your-pdf-filename-here.pdf#pag=[the-page-number]

or, if the file is within your localhost folder

http://localhost/your-path-here/your-pdf-filename-here.pdf#pag=[the-page-number]

epub

It is possible to link to a given location of an epub file, i.g. with calibre viewer, with a code like the following

file:///your-path-here/your-epub-filename.epub?open_at=epubcfi(/10/2/4/2/132/18/1:65)

You can get the string after open_at (in the above case: epubcfi(/10/2/4/2/132/18/1:65) in the calibre viewer, this way:

  • right click
  • -> go to
  • -> location
  • -> current location (above in the window) : copy

video file

with VLC you can use this code

vlc file:///my-path/my-video.mp4 --start-time=90

where ’90’ are the seconds (after the start of video).

I didn’t manage, so far, to open a video with such a code from a browser.

audio file

You ca do it in several ways. With play (sox) in Linux you can use a code setting not only the start time, but the end one as well:

play '/your-path/your-file.ogg' trim 5:18 =7:01

where 5:18 is the start time, and 7:01 the end one (=7.01 and not = 7:01)