How to get the space-key in the preview mode

Hello community. I developed a plug-in for confluence that adds a new macro. This macro needs the space-key as a parameter and I usually get it through AJS.Meta.get('space-key'). That works just great when a new page is being created/updated or displayed; however, if I click on the Preview button to see how the page will look after my edit, the mentioned statement returns undefined. Is there another way to get the space-key in the Preview mode? BTW, I also need to get access AJS.Meta.get('content-id') and AJS.Meta.get('content-type').

Thanks in advance.

Hey there, I’ve resolved my own issue. Turns out AJS.Meta.get('content-type') was not working for the page preview because its content is inside an iframe and the <meta> elements where the information is stored (and pulled from) are the parent document. Given this, I used jquery to look into the parent document if not found within the iframe as follows:

function getMetaAttribute(name) { return AJS.Meta.get(name) || AJS.$('meta[name="ajs-' + name + '"]', parent.document).attr('content'); };

then, instead of calling AJS.Meta.get('content-type') I just used getMetaAttribute('content-type') and it worked! Notice I had to prepend the ‘ajs-’ affix to match the name of the meta element; something that AJS.Meta.get must be doing internally :slight_smile: .