This commit is contained in:
parent
c97cb8c18b
commit
223a2fed97
|
|
@ -27,9 +27,11 @@ function enableNavigationInterception(assemblyName: string, functionName: string
|
|||
if (anchorTarget && anchorTarget.hasAttribute(hrefAttributeName) && event.button === 0) {
|
||||
const href = anchorTarget.getAttribute(hrefAttributeName)!;
|
||||
const absoluteHref = toAbsoluteUri(href);
|
||||
const targetAttributeValue = anchorTarget.getAttribute('target');
|
||||
const opensInSameFrame = !targetAttributeValue || targetAttributeValue === '_self';
|
||||
|
||||
// Don't stop ctrl/meta-click (etc) from opening links in new tabs/windows
|
||||
if (isWithinBaseUriSpace(absoluteHref) && !eventHasSpecialKey(event)) {
|
||||
if (isWithinBaseUriSpace(absoluteHref) && !eventHasSpecialKey(event) && opensInSameFrame) {
|
||||
event.preventDefault();
|
||||
performInternalNavigation(absoluteHref);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,34 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanFollowLinkToTargetBlankClick()
|
||||
{
|
||||
try
|
||||
{
|
||||
SetUrlViaPushState("/");
|
||||
|
||||
var app = MountTestComponent<TestRouter>();
|
||||
|
||||
app.FindElement(By.LinkText("Target (_blank)")).Click();
|
||||
|
||||
WaitAssert.Equal(2, () => Browser.WindowHandles.Count);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Closing newly opened windows if a new one was opened
|
||||
while (Browser.WindowHandles.Count > 1)
|
||||
{
|
||||
Browser.SwitchTo().Window(Browser.WindowHandles.Last());
|
||||
Browser.Close();
|
||||
}
|
||||
|
||||
// Needed otherwise Selenium tries to direct subsequent commands
|
||||
// to the tab that has already been closed
|
||||
Browser.SwitchTo().Window(Browser.WindowHandles.First());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanFollowLinkToOtherPageDoesNotOpenNewWindow()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,3 +20,5 @@
|
|||
<a id="anchor-with-no-href">
|
||||
Anchor tag with no href attribute
|
||||
</a>
|
||||
|
||||
<a href="/" target="_blank">Target (_blank)</a>
|
||||
|
|
|
|||
Loading…
Reference in New Issue