Sitelet https://github.com/flutter/flutter/issues/95060
Skip to content

[WebView] Add support for target property of anchor tag #95060

Description

@manuel-plavsic

Use case

The app I want to realize needs multiple WebViews, and inside each of them the anchor tag target property plays an important role, therefore the values should be distinguishable. In my specific case, <a href="/sitelet?url=https%3A%2F%2Fgithub.com%2Fflutter%2Fflutter%2Fissues%2FsomeURL" target="_blank"> URLs should open the link in the main browser, while <a href="/sitelet?url=https%3A%2F%2Fgithub.com%2Fflutter%2Fflutter%2Fissues%2FsomeURL" target="_self"> URLs should be opened inside the WebView. Support for "_top" and "_parent" could also be added.

Proposal

I think it would make most sense to introduce a target field, e.g., request.target, where request is of type NavigationRequest.

Snippet:

if (request.target == "_blank") {
  if (await canLaunch(request.url)) {
    await launch(request.url);
  }
  return NavigationDecision.prevent;
}
else {
  return NavigationDecision.navigate;
}```

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions