Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Safari Reader in a web page

Tags:

html

safari

I'm curious to know more about what triggers the Reader option in Safari and what does not. I wouldn't plan to implement anything that would disable it, but curious as a technical exercise.

Here is what I've learned so far with some basic playing around:

  • You need at least one H tag
  • It does not go by character count alone but by the number of P tags and length
  • Probably looks for sentence breaks '.' and other criteria

Safari will provide the 'Reader' if, with a H tag, and the following:

  • 1 P tag, 2417 chars
  • 4 P tags, 1527 chars
  • 5 P tags, 1150 chars
  • 6 P tags, 862 chars

If you subtract 1 character from any of the above, the 'Reader' option is not available.

I should note that the character count of the H tag plays a part but sadly did not realize this when I determined the results above. Assume 20+ characters for H tag and fixed throughout the results above.

Some other interesting things:

  • Setting <p style="display:none;"> for P tags removes them from the count
  • Setting display to none, and then showing them 230ms later with Javascript avoided the Reader option too

I'd be interested if anyone can determine this in full.

like image 701
donohoe Avatar asked Jun 08 '10 17:06

donohoe


People also ask

Can websites disable reader view?

There is currently no legit way of disabling Reader View for your website. Reader View is supposed to automatically detect on what pages it should be available and on what pages it should not.

How do I turn off the reader mode?

Tap at the left end of the address field, then tap Show Reader View. To return to the full page, tap , then tap Hide Reader View. Note: If Show Reader View is dimmed in the window, Reader view isn't available for that page.

Why does Safari open in Reader view?

The Reader mode, built into Apple's Safari browser since 2010 and available on macOS and iOS, strips away web advertisements and the page's navigational design to present an article's text and basic images in a clean and uncluttered format.

What is automatic reader on Safari?

Tap the Reader View icon in the top left of Safari. Select Website Settings from the dropdown menu. Turn on the toggle for Use Reader Automatically and press Done. The webpage will now automatically switch to Reader View every time you open it.


2 Answers

Adding markup to potentially "readable" tags, like p and div, can cause the Readability algorithm to ignore the tag, thus lowering the score, hopefully to a point that it doesn't trigger the Reader icon to display.

Looking at the Readability source, one area to do this is in the id and class attributes, as it does pattern matching on the combined data from these two attributes. For example, adding a "comment" class, like so

<p class="myClass comment">...</p> 

will cause that element to be ignored. The pattern that is being matched for "unlikely" candidates is:

/combx|comment|disqus|foot|header|menu|rss|shoutbox|sidebar|sponsor/i 

Placing flags on the elements that might add to the Readability Score can allow you to disable the Reader icon.

like image 187
Jeff Jenkins Avatar answered Sep 25 '22 06:09

Jeff Jenkins


“You need at least one <h*> element” — this is simply incorrect. Here’s an example: http://mathiasbynens.be/demo/safari-reader-test-3

My answer on the other Safari Reader question provides some more info.

You could also read my blog post on enabling Safari Reader for all my findings on the subject.

like image 26
Mathias Bynens Avatar answered Sep 24 '22 06:09

Mathias Bynens