7twenty Posted March 24, 2017 Report Share Posted March 24, 2017 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? Link to comment Share on other sites More sharing options...
7twenty Posted April 4, 2017 Author Report Share Posted April 4, 2017 So no one has any idea hey?! Link to comment Share on other sites More sharing options...
Tony Posted April 4, 2017 Report Share Posted April 4, 2017 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 Tony - Vivaldi 4 on Windows 10 64Bit Link to comment Share on other sites More sharing options...
7twenty Posted April 4, 2017 Author Report Share Posted April 4, 2017 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> Link to comment Share on other sites More sharing options...
bayas Posted April 4, 2017 Report Share Posted April 4, 2017 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 Link to comment Share on other sites More sharing options...
7twenty Posted April 6, 2017 Author Report Share Posted April 6, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts