Sign in to follow this  
Followers 0
7twenty

issue Two scripts with different entry points in one extension...

6 posts in this topic

I have two scripts. One that I want running at doc_start (script#1) and another on pressing the toolbar/sidebar button (script #2).

Script #1 calls for a function in Script #2, but seeing as they're separate scripts it fails at that point. Doing some reading it seems it can be done, and using the standard HTML code adding all scripts required for a page should allow that to work. But it seems when starting a script via an extension that has no effect, even if the HTML file that calls all the scripts is set to run as a background service.

Any tips on what I should be doing?

Share this post


Link to post
Share on other sites

So no one has any idea hey?!

Share this post


Link to post
Share on other sites

i have no idea apart from in the new UI they seem to do something similar in index and layout.htm - the latter is called in the former - have a look in there it may help - its simple so i would guess you have tried that

Share this post


Link to post
Share on other sites
28 minutes ago, Tony said:

they seem to do something similar in index and layout.htm - the latter is called in the former -

Nah, the equivalent in HTML for JS was tried as noted in the first post (code below). Just isn't working, or maybe not as I'm expecting. not sure if it's because it's an extension or something else.
I'd have this all sorted out had it not been for this. Been racking my head for a workaround which is getting more convoluted by the day. But this is the easiest and simplest method and I can't get it to work.

    <script type="text/javascript" src="js/file1.js"></script>
    <script type="text/javascript" src="js/file2.js"></script>

 

Share this post


Link to post
Share on other sites

You can only send or receive a message from one action (toolbar script) to another (page script) or vice versa. For example;

Toolbar script:

var mxRuntime = window.external.mxGetRuntime();

function getMessageFromPage(obj) {
  console.log('message: ' + obj);
}

mxRuntime.listen('messageFromPage', getMessageFromPage);

var button = document.getElementsByTagName("button")[0];
button.onclick = function(e) {
  mxRuntime.post('messageFromToolbar', 'Hi from Toolbar!');
}

Page script:

var mxRuntime = window.external.mxGetRuntime();

function getMessageFromToolbar(obj) {
  console.log('message: ' + obj);
}

mxRuntime.listen('messageFromToolbar', getMessageFromToolbar);

mxRuntime.post('messageFromPage', 'Hi from Page Script!');

 

1 person likes this

Share this post


Link to post
Share on other sites
On 4/4/2017 at 2:41 AM, bayas said:

You can only send or receive a message from one action (toolbar script) to another (page script) or vice versa.

Thanks for the info. Still trying to get my head around it, but it makes more sense now than when I first looked at the API documentation.

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0