Hi,
I'm creating Confluence pages using the REST API and everything works great, but how can I make external links on these pages to open in a new window/tab?
What I've tried in my XHTML is:
<a href="http://www.google.com" target="_blank">External link</a>
but the "target" property gets stripped upon submission.
I was thinking about doing the same thing with jQuery (as described here):
<script>
jQuery(document).ready(function() {
jQuery(".external-link").attr("target", "_blank");
});
</script>
but I'm unsure on how to inject this <script> into my page using the REST API.
I know this issue came up quite a few times here, but none of the answers addressed the REST API part of my question.
Thanks,
Piotr
Well I suggest cheating - create a simple user macro that formats the link how you want. Then your REST call can just inject the user macro.
<ac:structured-macro ac:name="link_macro" ac:schema-version="1">
<ac:parameter ac:name="link">http://www.google.com</ac:parameter>
<ac:parameter ac:name="link-text">External Link</ac:parameter>
</ac:structured-macro>
You could also add any custom CSS or classes to your macro to have a different styling for these type of links.
Thanks, Bill, that's a great workaround.
Sadly the macros are not enabled for me, so I'd prefer a solution which doesn't use one -- do you think that's possible?
Thanks,
Piotr
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well the problem you have is the one you are seeing - Confluence stripping some constructs from your XHTML. I have tried editing the source view of a page, to add attributes (for example, resetting a list number) - but as soon as the code is saved, what I have added has been filtered out.
And one way to inject the javascript on a page is via a user macro, or you need access to the admin console to add it across the site.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Bill, I guess we'll have to live with ctrl+left click for now.
Piotr
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.