Hi,
we would like to convert Word documents to html (using the FixedHTML save format). In the html result we would like to open all external links in a new tab but internal links of the document to jump to in the same tab.
Our first approach was to iterate all hyperlinks and setting the OpenInNewWindow
property to true
. However, in the HTML result the links still open in the same tab. I think this is a bug and hyperlinks should be supposed to open a new browser tab if OpenInNewWindow
is set.
We already found a workaround to set the Target
to _blank
instead. This also will open internal links in a new tab. In the documentation I found an example which checks if SubAddress != null
. Is this a safe way to differentiate between external and internal links of the document or is there a better way to do this?
I attached you an example for the issue with the OpenInNewWindow
property. You can reproduce the issue with the following code:
var lic = new License();
lic.SetLicense(@"S:\Aspose.Total.lic");
var doc = new Document(@"S:\tmp\links\test.docx");
// Prepare HTML Conversion
foreach (var hyperlinkField in doc.Range.Fields.Where(f => f.Type == FieldType.FieldHyperlink).Cast<FieldHyperlink>())
{
hyperlinkField.OpenInNewWindow = true; // links in html still will open in same tab
// workaround
/*if (hyperlinkField.SubAddress == null) // <- is there a better way to differentiate between internal and external hyperlinks?
hyperlinkField.Target = "_blank";*/
}
doc.Save(@"S:\tmp\links\out.html", SaveFormat.HtmlFixed);
Kind Regards,
Daniel
example.zip (76.3 KB)