0

I'm using Django to open some links in the same window, using webbrowser.

I wrote a custom action like this :

@admin.action(description='Open')
def open(modeladmin, request, queryset):
    for app in queryset.filter(auto_open=True).reverse():
        webbrowser.open(app.link, new=0, autoraise=True)

This is what happens when I check which links to open and click on Go :

  • If the window where the click originated is not incognito, it works fine, links are opened in the same window

  • If the window where the click originated is incognito, it does not work and links are opened in a non incognito window

What I'm trying to do here is to make sure that links will be opened in the same window, regardless if it's incognito or not. Is this browser specific ? Because I'm using Chrome and I don't know if I have to override settings or not

Amine Messaoudi
  • 2,141
  • 2
  • 20
  • 37
  • You need a way to determine a mode the page was opened in, and then specify the setting in `webbrowser` as suggested [here](https://stackoverflow.com/a/42912975/11544538) , or add your custom javascript in admin panel – Ersain Jan 14 '22 at 09:23
  • @Ersain The custom js seems to be a good option but how can I get the list of links in js ? So I can use `window.open(...)` on each link ? – Amine Messaoudi Jan 14 '22 at 14:11

0 Answers0