Electron.NET icon indicating copy to clipboard operation
Electron.NET copied to clipboard

Disable all external links

Open serdar-sahin opened this issue 4 years ago • 4 comments

Hi, firstly thank you for your great job.

How can i disable all external links in window? For example, let's open a youtube video page, but clicking on other links on the page does not open a new window.

serdar-sahin avatar Oct 26 '21 08:10 serdar-sahin

I use this snippet inside my windows

document.addEventListener('DOMContentLoaded', () => {
    document.addEventListener('click', (e) => {
      if (e.target.href && e.target.host != window.location.host) {
        e.preventDefault();
        e.stopPropagation();
        // do something else...
        return false;
      }
    }, true);
  });

danatcofo avatar Dec 06 '21 16:12 danatcofo

@danatcofo Thanks for your answer, but I need to change my question. I open a new window with youtube embed url. There are different links of youtube on the video screen that opens. Clicking on these links opens other windows. I want to block these windows.

serdar-sahin avatar Dec 08 '21 08:12 serdar-sahin

It's probably similar concept. Google it for a web page. It would be the same method in electron. Remember electron is just web pages with some raisins added.

danatcofo avatar Dec 08 '21 11:12 danatcofo

I guess an interception is not allowed inside the iframe.

serdar-sahin avatar Dec 10 '21 17:12 serdar-sahin

🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉

With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!

GregorBiswanger avatar Mar 28 '23 15:03 GregorBiswanger