readium / readium-shared-js

Repository for the shared JavaScript libraries that are used in the SDK-Launchers and other applications developed on top of the SDK
BSD 3-Clause "New" or "Revised" License
78 stars 102 forks source link

window.location.href in scripted EPUB HTML content documents messes-up the iframe state #275

Open danielweck opened 8 years ago

danielweck commented 8 years ago

In other words, dynamic hyperlink creation / activation and window.location redirect are not captured / intercepted by Readium. See internal_links_support.js and processLinkElements(): https://github.com/readium/readium-shared-js/blob/develop/js/views/internal_links_support.js#L180

danielweck commented 8 years ago

Original issues: https://github.com/readium/readium-js-viewer/issues/504#issuecomment-197804416 https://github.com/readium/readium-js-viewer/issues/508#issuecomment-197804546

danielweck commented 8 years ago

Is it possible to intercept window.location.href changes? Or to override the property? (probably does not work in all browsers though)

rkwright commented 8 years ago

Changed priority to High from Blocking. Would have made it medium except that the problem book was generated in InDesign

johanpoirier commented 8 years ago

I faced this very same issue today with a book from InDesign and I didn't found an acceptable way to solve it.

The only hack I found was to compare the iframe.src value with the iframe.contentWindow.location.href during the load event of the iframe. If those 2 values are different, we call the openContentUrl() method with the new URL. It kinda works but the content flashes and encrypted fonts don't work.

danielweck commented 8 years ago

Yes, it is a good idea to listen to the iframe load event, as any EPUB-scripted change to window.location.href would be detected there.

romaingiard commented 7 years ago

Hello, How and where do you listen to the iframe load event ?

johanpoirier commented 7 years ago

Hi,

You can see a load listener here: https://github.com/readium/readium-shared-js/blob/develop/js/views/iframe_loader.js#L86

danielweck commented 7 years ago

Well, in Readium (Chrome, hybrid, and native apps), there is a default "iframe loader" which sets up the onload() event callback on iframe HTML containers that are loaded with a plain src URL attribute: https://github.com/readium/readium-shared-js/blob/master/js/views/iframe_loader.js#L86

There is also a special "iframe loader" for the cloud reader that handles loading preprocessed EPUB content documents (e.g. HTML prefetched and supplied as binary Blob / BlobURI): https://github.com/readium/readium-js/blob/master/js/epub-fetch/iframe_zip_loader.js#L129

romaingiard commented 7 years ago

Thank you for your answers, johan could you please give me your source code for this function ?

danielweck commented 7 years ago

When the src of an iframe container is "forced" by scripts executed in EPUB HTML documents (typically, via window.location.href), several functions of the reading system are bypassed / not activated correctly. This includes: hyperlinking (internal to EPUB publication), obfuscated fonts, MathML / MathJax, Media Overlays, fixed layout scaling, etc. Basically, the reading system needs to take control over how/when EPUB content documents (HTML, SVG) are injected in iframe containers. There is an exhaustive description of RS responsibilities here: https://github.com/readium/readium-shared-js/wiki/ContentModifications

danielweck commented 7 years ago

So, when a "forced" change to iframe.src is detected, the reading system should intercept this, and "redirect" the URL request in order to a resume normal loading behaviour. Perhaps the best way to implement this in Readium is to wire-up a hyperlink action via: https://github.com/readium/readium-shared-js/blob/develop/js/views/internal_links_support.js#L180