Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 11-19-2010, 11:20 PM   #1
Vijay
Junior Member
Vijay began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Nov 2010
Device: ADE
Javascript in ePub.

How to embed javascript in ePub, anybody having samples or any resource.
Vijay is offline   Reply With Quote
Old 11-20-2010, 05:12 AM   #2
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 5,956
Karma: 4346919
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Javascript is not supported by the ePUB spec, nor by most ePUB readers.
Jellby is online now   Reply With Quote
 
Enthusiast
Old 11-21-2010, 11:35 PM   #3
Vijay
Junior Member
Vijay began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Nov 2010
Device: ADE
Quote:
Originally Posted by Jellby View Post
Javascript is not supported by the ePUB spec, nor by most ePUB readers.
so its not feasible to make animation or playing media in a ePub??
Vijay is offline   Reply With Quote
Old 11-22-2010, 12:51 AM   #4
wannabee
Media Bloke
wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.
 
Posts: 2,373
Karma: 113956855
Join Date: Sep 2010
Location: NSW - Australia
Device: iOS
Probably not what you want to do. Try this
wannabee is offline   Reply With Quote
Old 11-22-2010, 06:49 AM   #5
charleski
Wizard
charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.charleski ought to be getting tired of karma fortunes by now.
 
Posts: 1,188
Karma: 604284
Join Date: Sep 2009
Device: PRS-505
As Jellby said, the current standard doesn't provide for embedded media or scripting. There are a couple of non-standard solutions, though they should only be used if you are only targeting a specific reading device.

Here's Liza Daly's post on using JavaScript with iBooks. As with the other link, this will only work on the iPad.

Adobe's reading system will recognise flash elements, there's an example here. This won't work on the majority of device implementations, but does work on the desktop reader.
charleski is offline   Reply With Quote
Old 11-22-2010, 08:30 AM   #6
jharker
Developer
jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.jharker could sell banana peel slippers to a Deveel.
 
Posts: 345
Karma: 3473
Join Date: Apr 2007
Location: Brooklyn, NY, USA
Device: iRex iLiad v1, Blackberry Tour, Kindle DX, iPad.
Liza Daly's example (linked by charleski above) is a great place to start.

Two important things to note:
  • Inline scripts do not work in iBooks. You must write your script in a separate file and embed it using
    Code:
    <script type="text/javascript" src="script.js"></script>
  • Scripts aren't allowed to access remote files.
Also, I think I recall that you're limited to embedding ONE javascript file in your html. But I could be wrong about that.
jharker is offline   Reply With Quote
Old 11-22-2010, 07:57 PM   #7
whbenson
Enthusiast
whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.
 
Posts: 37
Karma: 493532
Join Date: May 2010
Device: ipad
FWIW, the following sample code works in both Sigil and iBooks.

Code:
 <?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
  <script type="text/javascript">
  //<![CDATA[
  alert("screen width=" + screen.width);
  //]]>
  </script>
</head>

<body>
</body>
</html>
Also, a workaround to editing javascript files in Sigil is to give the file a .css extension and put it in the Styles folder. Both iBooks and Sigil are happy with this.
-Bill
whbenson is offline   Reply With Quote
Old 11-24-2010, 02:20 PM   #8
Vijay
Junior Member
Vijay began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Nov 2010
Device: ADE
i tried with monocle reader, its too supporting javascript.
@ Bill. your example is good, i tried with that its working. thnks..
Vijay is offline   Reply With Quote
Old 09-27-2011, 09:26 PM   #9
killercatfish
Junior Member
killercatfish began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Sep 2011
Device: iPad
Hello!

I have watched liza's video and am pumped about the prospects for education. Any advice on where to read up/find examples on actually putting together an ePub with javascript and interactivity?

Thanks!
killercatfish is offline   Reply With Quote
Old 09-27-2011, 10:31 PM   #10
wannabee
Media Bloke
wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.wannabee ought to be getting tired of karma fortunes by now.
 
Posts: 2,373
Karma: 113956855
Join Date: Sep 2010
Location: NSW - Australia
Device: iOS
G'gay Killa' welcome to the forums.
You could try Liz Castro's comments.
Be aware that adding Java to an ePub will limit your audience. I don't think many reading devices will support it.
wannabee is offline   Reply With Quote
Old 11-07-2011, 06:46 AM   #11
gus_
Junior Member
gus_ began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Nov 2011
Device: ipad
bill, i have tried the exact code you posted, and it crashes sigil.

the alert window pops up twice, then a fatal error occurs.

i am using windows 7 64 bit and sigil 0.4.2

any ideas what may cause this behavior?
gus_ is offline   Reply With Quote
Old 11-07-2011, 07:20 AM   #12
Toxaris
Wizard
Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.
 
Toxaris's Avatar
 
Posts: 2,859
Karma: 2623257
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-300, PRS-T1
Could be anything. Javascript is not supported as far as I know and it is still not in the specifications of ePUB. So it is kind of hit and miss.
Toxaris is offline   Reply With Quote
Old 11-07-2011, 10:35 AM   #13
whbenson
Enthusiast
whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.
 
Posts: 37
Karma: 493532
Join Date: May 2010
Device: ipad
Quote:
Originally Posted by gus_ View Post
bill, i have tried the exact code you posted, and it crashes sigil.

the alert window pops up twice, then a fatal error occurs.

i am using windows 7 64 bit and sigil 0.4.2

any ideas what may cause this behavior?
gus - you're right (though I think it worked before). In any case this was just to demonstrate inline javascript was ok. More typically you'd put functions in the header and call them from the text. The sample below works in sigil 0.4.2, at least on the Mac. You could also invoke this from a link with the href attribute. <a href="javascript:hitme()">hit me</a>


Code:
<head>
  <title></title>
  <script type="text/javascript">
  //<![CDATA[
function hitme() {
  alert("screen width=" + screen.width);
}
  //]]>
  </script>

</head>

<body>
  <p onclick="hitme()">hit me</p>
</body>
</html>
whbenson is offline   Reply With Quote
Old 11-08-2011, 09:41 AM   #14
Jim Lester
Evangelist
Jim Lester is less competitive than you.Jim Lester is less competitive than you.Jim Lester is less competitive than you.Jim Lester is less competitive than you.Jim Lester is less competitive than you.Jim Lester is less competitive than you.Jim Lester is less competitive than you.Jim Lester is less competitive than you.Jim Lester is less competitive than you.Jim Lester is less competitive than you.Jim Lester is less competitive than you.
 
Jim Lester's Avatar
 
Posts: 416
Karma: 14682
Join Date: May 2008
Location: SF Bay Area
Device: Nook HD, Nook for Windows 8
Quote:
Originally Posted by Toxaris View Post
Could be anything. Javascript is not supported as far as I know and it is still not in the specifications of ePUB. So it is kind of hit and miss.
Javascript is allowed in EPUB3 documents, but not EPUB2 documents. Any Reader that is not using WebKit (ie Adobe RMSDK) will only handle EPUB2 documents, and that's the vast overwhelming majority right now. As mentioned above, iBooks is the closest to an EPUB3 reader that is out there right now.
Jim Lester is offline   Reply With Quote
Old 11-08-2011, 01:30 PM   #15
whbenson
Enthusiast
whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.whbenson ought to be getting tired of karma fortunes by now.
 
Posts: 37
Karma: 493532
Join Date: May 2010
Device: ipad
Quote:
Originally Posted by Jim Lester View Post
Javascript is allowed in EPUB3 documents, but not EPUB2 documents. Any Reader that is not using WebKit (ie Adobe RMSDK) will only handle EPUB2 documents, and that's the vast overwhelming majority right now. As mentioned above, iBooks is the closest to an EPUB3 reader that is out there right now.
Just for the record, one other webkit based reader with Javascript is the Kobo app for iOS.
whbenson is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
epub et javascript zelda_pinwheel Software 9 12-09-2010 04:56 PM
Javascript and Bookmarklets Polvo Kindle Developer's Corner 0 10-17-2010 05:54 AM
I need Javascript help Nate the great Workshop 4 04-04-2009 12:55 AM
iLiad Javascript? jsc iRex Developer's Corner 1 09-10-2006 07:17 AM
Can this be done - remove javascript from a page ScottMattes Workshop 1 05-17-2006 01:27 AM


All times are GMT -4. The time now is 05:16 AM.


MobileRead.com is a privately owned, operated and funded community.