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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

target="_blank" in Html Email

Post Reply
KenS
Posts: 28
Joined: Sat Aug 10, 2024 12:44 am
Location: Australia

target="_blank" in Html Email

Post by KenS »

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
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: target="_blank" in Html Email

Post by salvadordf »

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 :

Code: Select all

for (const element of document.getElementsByTagName("a")) { element.removeAttribute("target"); }
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.
KenS
Posts: 28
Joined: Sat Aug 10, 2024 12:44 am
Location: Australia

Re: target="_blank" in Html Email

Post by KenS »

salvadordf wrote: Sun Aug 25, 2024 4:53 pmIf you prefer removing the "target" attribute try executing this JavaScript code to remove all of them :
Yeah but I know more Delphi than JS :D
Copied your code, works great.
Just execute that JS code as soon as the page is loaded.
Chromium AfterCreated?

All works!

Ken
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: target="_blank" in Html Email

Post by salvadordf »

KenS wrote: Mon Aug 26, 2024 4:53 am
Just execute that JS code as soon as the page is loaded.
Chromium AfterCreated?
That event is triggered too soon. Try executing the JavaScript code in TChromiumCore.OnLoadingStateChange when "isLoading" is false, or in TChromiumCore.OnLoadEnd.
Post Reply