As discussed in another post, if I open an HTML email and a link contains target="_blank" the link will not work. You pointed out that SimpleBrowser2 does not support multiple browser windows - all ok.
Just before using Chromium.DefaultURL and Chromium.LoadURL I now scan the HTMLBody and change those links to remove the target. I then write the HTML to a temp file and pass that instead.
Questions:
What does DefaultURL do?
I tried Chromium.LoadString rather than a temp file but ended up with an empty window - any tricks I need to do?
A minor problem with the above approach is that is that (I think) if the second window also contains a target my program has control of Chromium at that stage to try and remove targets. Is there any easy way around this - I am not too fussed with it and can easily just live with it
Thanks
Ken
Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
target="_blank" in Html Email
- salvadordf
- Posts: 4620
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: target="_blank" in Html Email
Hi,
DefaultURL is used to navigate to a URL automatically as soon as the browser is created.
A simple solution could be to cancel the navigation in OnBeforeBrowse and open the link in the current browser as described here :
https://www.briskbard.com/forum/viewtopic.php?t=2131
This solution works fine when the link uses a simple GET method but it fails with POST methods.
If you prefer removing the "target" attribute try executing this JavaScript code to remove all of them :
Just execute that JS code as soon as the page is loaded. It shouldn't be necessary to create a copy in a temp file.
DefaultURL is used to navigate to a URL automatically as soon as the browser is created.
A simple solution could be to cancel the navigation in OnBeforeBrowse and open the link in the current browser as described here :
https://www.briskbard.com/forum/viewtopic.php?t=2131
This solution works fine when the link uses a simple GET method but it fails with POST methods.
If you prefer removing the "target" attribute try executing this JavaScript code to remove all of them :
Code: Select all
for (const element of document.getElementsByTagName("a")) { element.removeAttribute("target"); }
Re: target="_blank" in Html Email
Yeah but I know more Delphi than JSsalvadordf wrote: Sun Aug 25, 2024 4:53 pmIf you prefer removing the "target" attribute try executing this JavaScript code to remove all of them :

Copied your code, works great.
Chromium AfterCreated?Just execute that JS code as soon as the page is loaded.
All works!
Ken
- salvadordf
- Posts: 4620
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: target="_blank" in Html Email
That event is triggered too soon. Try executing the JavaScript code in TChromiumCore.OnLoadingStateChange when "isLoading" is false, or in TChromiumCore.OnLoadEnd.KenS wrote: Mon Aug 26, 2024 4:53 amChromium AfterCreated?Just execute that JS code as soon as the page is loaded.