Copy link to clipboard
Copied
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--;
}
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.
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:
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...)
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
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.
Copy link to clipboard
Copied
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:
PS: test.txt is actually the js file to be renamed.
HTH
Loic Aigon