• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Running js using a button (indesign, fixed format, epub)

New Here ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

Looking to run the below script from an exported fixed formatted epub, using a button. Is this possible?
 

 

var doc = app.activeDocument;

for (var i = 0; i < doc.pages.length; i++) {
  var page = doc.pages[i];
  page.select();

  var multiState = page.multiStateObjects.itemByName("Multi-state-1");
  multiState.activeStateIndex--;

}

 

TOPICS
EPUB , Scripting

Views

602

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 02, 2023 Mar 02, 2023

Copy link to clipboard

Copied

You can add JS to an EPUB export in the Export Options | JavaScript dialog.

 

I don't know anything about how to hook it in from within InDesign, though.

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

Once the ePub is done, the end-product has no connection at all with InDesign DOM so your code cannot work at all as fired from a button inside the ePub.

I would look at button interactivity options inside InDesign. Here is an example:

Capture d’écran 2023-03-03 à 09.49.02.pngCapture d’écran 2023-03-03 à 09.49.10.pngbutton.gif

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

So what is the use of the JS code at export time? If it can't be linked to internal functions like buttons, why is it offered at all? (It's one of the areas of EPUB export about which I know next to nothing, but I can't believe Adobe would just stick that option in there for no good purpose...)

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

I was pointing out the fact the code our friend wanted to run was ExtendScript related to InDesign. I think it's quite obvious that if the ePub once opened in an external application (or think of a Kindle) cannot execute a code that normally is executed through the InDesign Script engine. 

Once that said, I am not the ePub expert but the js there is mostly to be run by the reader app and the code is likely to be vanilla javascript, not InDesign ExtendScript. 

I tried to find some Adobe literature on the topic without much luck but I happily delegate this to our friend.

Loic

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

I missed that it was ID code.

 

I really need to find an answer to this; I am not a JS or script wizard but the question of how to hook JS into EPUB exports has come up before.

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

LATEST

Ok, so here is a super dummy example but that works. Say I created a button inside InDesign. I want that if I click on the button inside the ePub reader, an alert is thrown.

 

What I needed for my example, was a first blank export so I could spot an element ID (_idContainer005 for my demo)

With this specific id in mind, I created this little js code and saved to a file:

 

 

document.addEventListener("DOMContentLoaded", function() {
    document.getElementById("_idContainer005").onclick = function(e){
        alert("ici")
    }
  })

 

 

Then I export to ePub again attaching the js file.

And now if I click on the ePub, I get the alert. It's super dumb but at least you get the idea.

Once again, not the ePub guy, so there may be much better things to do, just suggesting one here:

LoicAigon_0-1677887270048.png

PS: test.txt is actually the js file to be renamed.

 

HTH

Loic Aigon

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines