0

I have created a web app (using flask) in which there are some links like follow:

<a target="_blank" href=" https://in.tradingview.com/chart/?symbol=NSE:ACC1! ">ACC</a> 
<a target="_blank "  href="https://in.tradingview.com/chart/?symbol=NSE:ADANIENT1! ">ADANIENT</a> 
<a target="_blank "  href="https://in.tradingview.com/chart/?symbol=NSE:ADANIPORTS1! ">ADANIPORTS</a>

when this links are clicked, the respective page opens, and after loading the page, following popup window is shown on that page. enter image description here

one way to close this popup is by clicking the cross symbol and other is to press escape key.

it is annoying to do this on each page i visit.

i want to Programmatically press escape when the page loads completely.

i refered to this question Press Ctrl+c keys automatically onload

difference between this question and mine is that i want to press escape key on the page that is opened when link is clicked and not on the page that i am currently on

when searching for solution i came acroos the onload function in javascript i am beginner in javascript.

i want to know how can i use this function on the new page that is loaded.

if question is not clear

this is what exactly i want to do:

  1. user clicks the link on my webapp
  2. he gets redirected to respective webpage
  3. when the webpage loads completely, escape key should get pressed on that page so that popup window gets closed.

Note that my webapp is not a public-facing site; I am the only user.

update 2:

after blocking elements unable to access the page normally.

before after

user4599
  • 77
  • 3
  • 11

3 Answers3

0

Note: the answer below assumes that other people will be using this page.

Given that you are the only user, then uBlock Origin as suggested by @bluevulture should do the trick!


If the pages you link to are not under your control, then you can't do this.

When your visitor clicks one of those links, your page is unloaded completely, including all your JavaScript code. Then the new page loads, and you have no way to affect it at all.

If you own the target pages, then you could add some JavaScript code in those pages themselves. But if you had control over those pages, you could probably just change their code to not show the popup in the first place.

You could possibly do this with a Chrome extension (or a similar extension for other browsers), but your visitors would have to install this extension and give it full access to all web pages. They may be reluctant to do that.

Michael Geary
  • 28,450
  • 9
  • 65
  • 75
  • is there any extension available for chrome to do so? – user4599 Apr 21 '21 at 07:50
  • No idea. You would have to do some searching, or get ambitious and write your own extension. But remember that your page can't just load an extension on its own. You would have to persuade visitors to install the extension. – Michael Geary Apr 21 '21 at 07:52
  • 1) i dont own target pages, 2) only i am gonna use this webapp so installing extension is no issue, – user4599 Apr 21 '21 at 07:53
  • 1
    [UBlock Origin](https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm?hl=sl), has the ability to remove elements from a page, and the ability to add filters that do that for you. It's what I use to do exactly what you want. – bluevulture Apr 21 '21 at 07:54
  • i dont have experience writing code in javascript, i am looking for solution in python preferably. – user4599 Apr 21 '21 at 07:55
  • uBlock Origin as suggested by @bluevulture is an excellent idea! I would try that. You shouldn't have to write any JavaScript code. – Michael Geary Apr 21 '21 at 07:56
  • @bluevulture UBlock Origin blocks popups on the current page, not on the pages that i am about to visit – user4599 Apr 21 '21 at 08:01
  • Go to the target page and then enable the popup blocker (or more specific rules) for that site. – Michael Geary Apr 21 '21 at 08:05
  • @user4599, you can create a rule that applies to an entire domain (or subdomain), using [dynamic filtering](https://github.com/gorhill/uBlock/wiki/Dynamic-filtering) – bluevulture Apr 21 '21 at 08:07
  • @bluevulture Would you like to write up your uBlock Origin suggestion and tips as an answer? Then I will upvote your answer and delete this one as it wasn't relevant to OP's needs. – Michael Geary Apr 21 '21 at 08:19
  • And @user4599 I took the liberty of adding a note to your question explaining that you are the only user of the webapp. – Michael Geary Apr 21 '21 at 08:21
0

For removing popups or other elements on a webpage (for your own personal use) you can use UBlock Origin, an AdBlocker which has support for dynamic filtering, so you can add a filter/rule to remove the popup on a domain and/or subdomains.

It's also fairly easy to use:

Blocking

bluevulture
  • 422
  • 4
  • 16
  • with dynamic filtering i was able to block the element, but after this, unable to access the page as before, i tried multiple elements and preview but no luck. i have updated the images in question, i think blocking the element is not the correct way, i need to write extension that will press escape key when page loads. – user4599 Apr 21 '21 at 08:59
  • @user4599 A modal popup is usually made-up of two elements: the popup itself and a div over the entire webpage that darkens it. Try blocking both. Some might have more elements. – bluevulture Apr 21 '21 at 09:10
0

Press f12 to open developer tools and then open the inspector tool (control shift C if you are using chrome) then click on the cross that you want to programmatically click. You will see that the element has an id, if it does not then add an id to that element in your HTML. Once you know the id, insert this at the end of your HTML:

<script>
let target = document.getElementById("id-goes-here");
target.click();
</script>
Costa
  • 1,794
  • 1
  • 12
  • 21
  • i dont have access to the target page, i cant add this code to the html code of that page, – user4599 Apr 21 '21 at 08:40
  • your answer is similar to this https://stackoverflow.com/a/29272268/14713550 which is different from my question – user4599 Apr 21 '21 at 08:41