I would very much like to have external links automatically open up in a new window (e.g. target="_blank") while internal links remain in the same window.
Is it possible to set this as a default somehow?
I would very much like to have external links automatically open up in a new window (e.g. target="_blank") while internal links remain in the same window.
Is it possible to set this as a default somehow?
Problem resolved by going to: Administration Wiki, Look & Feel, Presentation, HTTP Meta Info
and adding the following into the meta box
<script>
function fixExternalLinks() {
document.querySelectorAll('.wikiexternallink a').forEach(function(link) {
if (link.hasAttribute('target') == false) {
link.setAttribute('target', '_blank');
}
})
}
document.addEventListener("DOMContentLoaded", fixExternalLinks);
</script>indent preformatted text by 4 spaces
Now, any link that xwiki thinks is an external link and has no predefined target now has a target to a new window.
(This might break something else later, but so far it works)
Cool. Note that thereâs another (possibly cleaner) way of doing this. Use a JSX object with a wiki level scope.
See http://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/SkinExtensionsTutorial/
Thanks for posting back your solution! Thatâs great
Yes, I looked briefly at making a skin, and then decided that it was more effort than I needed.
I was more interested in something quick that requires little, if any, maintenance as the software changes.
Hmm⌠Looking more closely, A skin extension maybe just the right way to do it. Iâll have a look at that when I have a bit more free time to see if I can make that work.
yes itâs not a skin, just a way to inject CSS or JS when viewing a given page or when viewing any page.
Hi,
I have a question linked to this subject: in version XWiki 9.11.1, why the popup to define an URL/link properties does not contain âtargetâ attribute anymore? I find this annoying or maybe I missed something? (I use a Wiki hosted on myxwiki.org).
Thanks for your answer,
If youâre talking about CKEditorâs WYSIWYG, see http://extensions.xwiki.org/xwiki/bin/view/Extension/CKEditor%20Integration/#HAdministrationSection
Note that AFAIK this has always been like this since we introduced CKEditor. Maybe youâre remembering some old feature with the GWT WYSIWYG editor?
Thomas, youâre âtwiceâ right: I was used to the old WYSIWYG editor and itâs easy to change the new CKEditor behaviour.
Many thanks for your quick and relevant answer.
Vincent maybe ?
lol
I did it! I created my first skin extension using this JS code!
Well done!
Well, geez, I never tested this in Internet Explorer - works fine in Chrome, but not at all in IE and we use IE a lot still here at work.
function fixExternalLinks() {
document.querySelectorAll('.wikiexternallink a').forEach(function(link) {
if (link.hasAttribute('target') == false) {
link.setAttribute('target', '_blank');
}
})
}
document.addEventListener("DOMContentLoaded", fixExternalLinks);
Object doesnât support property or method âforEachâ
Sorry laurin1, I didnât test with IE as I consider the browser too old and out of date to support.
Can you tell me what version of IE you are using and Iâll see if I can find a workaround for you.
IE 11, which supports almost all of the modern web development standards. I know people donât like it, but in an Active Directory domain, we still have more control over it in an enterprise environment and so that is still our standard internally. Iâve reviewed the code (Iâm a web developer myself) and I actually donât see why it would not work.,
document.querySelectorAll is supported in IE (since version 8), except with pseudo classes, which this is not using. Given some time, I can write the JS necessary to fix this, so donât spend too much time on it, Iâm sure I can hammer it out eventually.
As an aside, Iâm using chrome in an AD environment, and I can set all the useful defaults in the group policies.
Looks like IE is not implementing forEach on the the nodelist querySelectorAll provides. But a standard for loop should work.
Something like
nodes=âŚquerySelectorAll()
for(var i=0; i< nodes.length; i++){
// do sth. with nodes [i]
}
Obviously this is only pseudo code and I did not try it, put typing this little code on a mobile is already killing me
Well, itâs your thread we are hijacking, but yes, we use those for the limited usage of Chrome we allow, but they are not as granular (and some just donât work as well) for Chrome - we are healthcare and keep things locked down pretty tight here. Still, we are evaluating what our next option will be, but we will possibly move to Edge and not Chrome - the main reason is that, while the us IT people love Chrome, itâs a resource hog (and Iâve got the stats to prove it), and we have some older hardware out there. Still, we are considering Chrome as an option, depending on the how the next iteration or two of of Edge goesâŚ
I considered that as well and just needed time to test it - thanks for the leg up!