0

I have been trying to load a custom javascript to be loaded in all my alfresco pages.

I need to add a listener, so an external application can access the current url loaded at alfresco using an iframe.

The listener would be something like this: (copied from this question)

window.addEventListener('message', function(event) {

    // IMPORTANT: Check the origin of the data!
    if (~event.origin.indexOf('http://yoursite.com')) {
        // The data has been sent from your site

        // The data sent with postMessage is stored in event.data
        console.log(event.data);
    } else {
        // The data hasn't been sent from your site!
        // Be careful! Do not use it.
        return;
    }
});

It can be either appended at every page or loaded as an external .js file.

Thanks for your time.

Community
  • 1
  • 1
Daerum
  • 111
  • 9

1 Answers1

1

First, check the Alfresco documentation.

For the target, you can choose either the footer or header regions.

Then in your extension, include your js file with the @script markup.

izodev
  • 135
  • 8
  • That link uses version 4.2 version as the target. Searching the same for the version 5.0 and following exactly what is told in the example ended up downloading version 5.1.e which isn't what I wanted to do. I don't know if you are familiar with alfresco at all. But it is hard to find any single straightforward article on the documentation that works as expected you can notice it by looking at the number of stars on each Article (I haven't found anything with more than 2 stars). That is why I ended up asking the question in Stackoverflow. Anyway, thanks for your effort. – Daerum Aug 25 '16 at 14:05
  • This approach is valid since the version 4 and it's the case for the 5.x versions. Also, I have tested it and it works. What's exactly your problem and why you have downloaded the 5.1.e version ? – izodev Aug 26 '16 at 22:31
  • As I said. I moved to 5.0 version, and followed all the steps and executing the last command installed the 5.1.e version. Probably the error comes from the step that says "Create a suitable directory in which to store all your Maven projects (if you have not already done so), such as alfresco-extensions.". I created it outside alfresco, where I store all my projects. I think that that folder should be somewhere within alfresco. Anyway, since I was in a hurry I ended modifying the Alfresco footer file and made it work. – Daerum Aug 29 '16 at 07:38