How to react to doubleclick event on tab ?
-
Hello,
How to detect we doubleclick on a specific tab (tabheader for example)?
thanks in advance.
-
-
Thanks. I'm beginner in vivaldi and browser scripting. I try a minimalist test into a .js file declared into browser.html... nothing :
#browser.tab.ondblclick = docdblclickhandler; function docdblclickhandler() { alert("The document is double clicked..."); }
If I've in mind in a second-step to launch a vivaldi tiling function (I don't how it would be hard to do this...), can we also catch doubleclick into style css file according to this way (it also doesn't run for me...) ?
.tab.ondblclick { border-top: blue !important; padding-right: 5; }
-
Check console for error, then you know what's wrong.
-
@seasonly Just a few hints. You can't just input css selectors like this, they need a
document.querySelector
or something. The next problem is that the code runs before the tabs are loaded. Therefore you need something that checks for the existence of your element and then runs the code. Look at other mods on here and you will see how it works.Working example:
setTimeout(function wait() { var tab = document.querySelector('.tab-header'); if (tab != null) { tab.addEventListener('dblclick', function() { tab.style = "background-color: red !important"; }); } else { setTimeout(wait, 300); } }, 300);
edit: my code is wrong too, of course, because querySelector will only select the first tab-header, you would need to iterate through them somehow.
-
@luetage
I don't see anything... The first tab-header doesn't change its background. -
@seasonly Doesn't matter, since you need different code to accomplish what you desire.
-
I looked into it again, this works:
setTimeout(function wait() { var browser = document.getElementById('browser'); if (browser != null) { browser.addEventListener('click', function() { var tabs = document.getElementsByClassName('tab-header'); for (var i=0; i < tabs.length; i++) { tabs[i].addEventListener('dblclick', function(i) { tabs[i].style = "background-color: #fd3563"; }.bind(this, i)); } }); } else { setTimeout(wait, 300); } }, 300);
-
I'm sorry but if now the objet is catched, it seems that it doesn't want to execute tab style code line... and nothing changes.
-
@seasonly I have tested this without any other modifications running. It changes the background color of every tab that is double-clicked. There are no error messages in the console and it even triggers on newly created tabs. I'm sorry if it doesn't work for you, but you will simply have to find out what's different in your setup and adjust the code. I would try it on a new and untouched Vivaldi installation in your stead.
edit: I'm on latest snapshot.
-
Tried on stable, seems to work correctly here with other mods.
Change background colour on doubleclicked tabs. -
I've finally made it to work. Thanks a lot for the help.
-