Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Allow file access outside widgets, in ibook author html (dashboard) widgets

Hello,


I am trying to access JavaScript files outside the widget (but they are saved locally). When I embed the html/dashboard widget in ibook Author, the html widget on ibook doesn't run the JavaScript.


I did this at first using the html tag:


<script type="text/javascript" language="javascript" src="path of file that is saved outside the widget">....


And since ibook author doesn't support the key AllowFileAccessOutsideOfWidget, I would like to know if there is a way to link/access files (Javascript files) outside the widget?.


My JavaScript is the base functionality for many pages (mathematical material), I don't want to add the functionality everytime inside a widget, because it is huge in size >30MB. Is there any way to overcome this problem, while accessing the scripts should be done locally (so it works offline).


Many thanks

Rana

Posted on May 17, 2012 1:31 AM

Reply
5 replies

May 17, 2012 2:37 AM in response to rmdissa

rmdissa wrote:


<script type="text/javascript" language="javascript" src="path of file that is saved outside the widget">....


Hmmm… I have no problem with the following:


<script type="text/javascript" src="main.js" charset="utf-8"></script>


main.js lives in the root directory of the widget.


Is the script file you are trying to run inside the widget bundle? If not, I'd try putting it there.


I take it that you remembered to provide the start function for the script? Something like


<body onload="load();">

...

</body>


Michi.

May 17, 2012 2:53 AM in response to MichiHenning

Hello Michi,


No, I didn't add onload="load();" to the body of html. I am not using Dashcode to create my html/JavaScript code.


You have mentioned that src="main.js" works for you, but how if you try to put the main.js outside the widget directory (or if you call it widget bundle) and link it using the html tag as follows:


src="../code/web/main.js">



What happens then? In my case, the JavaScript is not called. And that is my problem I would like to solve.


Many thanks

Rana

May 17, 2012 3:01 AM in response to rmdissa

rmdissa wrote:


Hello Michi,


No, I didn't add onload="load();" to the body of html. I am not using Dashcode to create my html/JavaScript code.

You have to specify a start function, otherwise the browser run time has no idea which function in your Javascript to call. This is necessary whether you use Dashcode or not.


You have mentioned that src="main.js" works for you, but how if you try to put the main.js outside the widget directory (or if you call it widget bundle) and link it using the html tag as follows:


src="../code/web/main.js">


What happens then? In my case, the JavaScript is not called. And that is my problem I would like to solve.

I strongly suspect that the script you want to call must be inside the widget bundle. It is highly doubtful that the script would be allowed to access any other part of the iBooks bundle. (I haven't verified this, but I would expect that to fail.)


I would first up make a very simple JavaScript that sits inside the widget bundle and displays something. Verify that this works. You will need to specify which function to call in response to the onload event.


Now, I have absolutely no idea how you would put your Javascript elsewhere. One approach you could try is to unzip the .ibooks file, put the Javascript code somewhere inside it, and modify your HTML to try and use that script. Then see whether it runs.


If not, I suspect you are out of luck. And I would expect the script be prevented from accessing any files outside its own widget bundle because, otherwise, the script could escape from its sandbox and do all sorts of malicious things.


Michi.

May 17, 2012 10:49 PM in response to MichiHenning

Hello Michi,


Thanks a lot for your reply. I am also now suspecting that what I want to do is possilbe.


However, talking about the onload() method. I am able to make my widget work when I have the JavaScript inside the widget bundle. I don't have now problems with that, but we (the group) are trying to find a way to minimize the size of the widget and consequently the size of the ibook file.


I also, thought of your suggestion of unzipping the file today. I will try it and will let you know.


Many thanks for your thorough explanation

Rana

May 17, 2012 11:39 PM in response to rmdissa

rmdissa wrote:


However, talking about the onload() method. I am able to make my widget work when I have the JavaScript inside the widget bundle. I don't have now problems with that, but we (the group) are trying to find a way to minimize the size of the widget and consequently the size of the ibook file.

Well, you can put Javascript inline between the <script> tags and call a function from there. In that case, the script will start running even before the page has completed loading. The approach that is generally taken is to specify a start function, such as load(), which is called in response to the onload event, which doesn't fire until after the page has finished loading.


Please let us know what you learn!


Michi.

Allow file access outside widgets, in ibook author html (dashboard) widgets

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.