Skip to content

Creating empty value for attributte #552

@joffremota

Description

@joffremota

1. Description

I've got the following value
<a download href=\"/downloads/arquivo.zip\">Download do Arquivo</a>

When I pass this into the following method in order to add the target="_blank" attributte, I'm getting this:
<a download="" href=\"/downloads/arquivo.zip\" target=\"_blank\">Download do Arquivo</a>

How can I prevent the lib to add the empty value on download?

Here is the method.

        private string UpdateAnchorTagsWithTargetBlank(string html)
        {
            var doc = new HtmlDocument();

            doc.LoadHtml(html);
            var anchorNodes = doc.DocumentNode.SelectNodes("//a[@href]");
            if (anchorNodes != null)
            {
                foreach (var node in anchorNodes)
                {
                    if (node.GetAttributeValue("target", "") != "_blank")
                        node.SetAttributeValue("target", "_blank");
                }
            }

            return doc.DocumentNode.OuterHtml;
        }

2. Exception

Not applicable

3. Fiddle or Project

Not applicable

4. Any further technical details

  • HtmlAgilityPack (1.11.40)
  • SDK Version: 6.0.404

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions