I've just applied this patch and, yes, it's great that http:// links open in a new window, it helps to keep things clear. But the fact that the saved version of an edit (upon pressing Save) opens in a new window is more confusing, particularly as the edit window remains open. Is this fixable?? StephenHay
Can someone fix this ^^ i would only like to have external links / intermap to open in a new window. I cant find where to add the target="_blank" ...
Ok i changed this
if ($useImage && &ImageAllowed?($url)) { return "<img src=\"$url\">"; } return "<a href=\"$url\">$name</a>";}
to
if ($useImage && &ImageAllowed?($url)) { return "<img src=\"$url\">"; } return "<a href=\"$url\" target=\"_blank\">$name</a>";}
Dont know if this is right but it seems to work for me...
Step 1 - add this to the list of global use vars
$PopWindows
Step 2 - add the following below the list of # Major Options:
# Patch for WikiPatches/OffsiteNewWindow $PopWindows = 1; # 1 = offsite links target _blank, 0 = all links target _selfStep 3 - within sub ScriptLink add
my $target = ""; if ($PopWindows) { $target = "target=\"_self\""; } else { $target = ""; }Step 3a - in the same sub routine (ScriptLink) change the return line so that it reads
return "<a $target href=\"$ScriptName?$action\">$text</a>";
Step 4 - within sub routine GetHtmlHeader add
if ($PopWindows) { $html .= qq(<BASE target="_blank">\n); }
$OffsiteNewWindow = 0; # 1 = Offsite links open in new window
Then I changed the last line of UrlLinkOrImage? to:
my $target = ''; $target = 'target="_blank"' if ($OffsiteNewWindow); return "<a href=\"$url\" $target>$name</a>";
and the last line of StoreBracketUrl? to:
my $target = ''; $target = 'target="_blank"' if ($OffsiteNewWindow); return &StoreRaw("<a href=\"$url\" $target>$text</a>");
These changes make it so that all unencapsulated URLs, bracket URLs starting with http, InterWiki links, and links to uploaded files open in new windows, leaving other links unchanged.
-- Mapache
I modified your code a bit to allow for pages from my [site] to load in the same window. I added a configuration option to hold a string to be compared:
$OffsiteNewWindow = 0; # 1 = display in new window 0 = display in same window $OnsiteBase = ''; # If entered will not be displayed in a new window
and modified the if statements above:
$target = 'target="_blank"' if ($OffsiteNewWindow && $url !~ /$OnsiteBase/i); return "<a href=\"$url\" $target>$name</a>";
-- BobBreedlove
A couple of addon notes to these patches . . .
-- DarrinLowery?
I've added an option to cause offsite site links to spawn a new window
my $target = ""; if ($PopWindows) { $target = "target=\"_self\""; } else { $target = ""; }
if ($PopWindows) { $html .= qq(<BASE target="_blank">\n); }what would be nice is for a user to select their preference --EricScheid Unfortunately if you make that a user preference, it will break the page caching feature.
Using the <BASE> tag is just plain incorrect, period. It is a head-level tag, for one. It changes the default for all links on the page globally, and the fact that it happens to work on some browsers and not do so for links previous doesn't change the intended behavior -- browsers may eventually fix their behavior. You need to set the target= attribute per-link. I don't have the script handy to tell you where at the moment, but ScriptLink is most likely at least one place it needs to be done. --ChuckAdams