Open all links from a page in a new / same tab
-
These are merely a variation of my Follower Tabs script and I didn't make them earlier because I didn't think anyone would find them useful, but since it's just a simple script, I decided to share it.
Open all links from a page in a new tab
It opens every link on a page (when clicked) in a new tab.
Method 1 - Bookmarklet
- Save the following code as a bookmark:
javascript:var linksArr=document.getElementsByTagName("a");for(i=0;i<linksArr.length;i++){linksArr[i].setAttribute("target","_blank");};
- Put the bookmark on your bookmarks bar or wherever you find the most convenient for you.
- Use the bookmark to set all links on the page to open in a new tab. After refreshing the page, they'll revert back to the default behaviour.
Method 2 - Page Actions
- Go to your Vivaldi installation folder and navigate to the Page Actions catalogue (
located at *Vivaldi installation folder*\Application\*Vivaldi version number here*\resources\vivaldi\user_files\
) - Create a new file (a text document) or make a copy of one of the existing files and wipe its contents.
- Change the file's name to "Open links in New Tabs" (you can name it however you wish) and change its extension to
*.js
, so it looks like this:Open links in New Tabs.js
- Paste the below code into your file and save it.
- Restart Vivaldi (or run, if it wasn't running already).
- Choose Page Actions from the status bar (by default press
[CTRL]
+[SHIFT]
+[S]
/[cmd ⌘]
+[shift]
+[S]
to show/hide the status bar) - its icon looks something like this:<>
- and find your "Open links in New Tabs" Page Action on the list. - Alternatively, call the Page Action using the quick commands menu (by default press
[F2]
) by simply typing its name (the one you've chosen in step 3). - Page Actions work for all websites within the tab in which they were enabled. To restore the default behaviour, turn off the Page Actions (the page will refresh).
Use this code:
function OpenInNewTabs() { var linksArr=document.getElementsByTagName("a"); for (i=0;i<linksArr.length;i++) { linksArr[i].setAttribute("target","_blank"); } } if (document.readyState==='complete') { OpenInNewTabs(); } else { document.addEventListener('DOMContentLoaded', function() { OpenInNewTabs(); }); }
Open all links from a page in the same tab (reuse existing tab)
It opens every link on a page (when clicked) in the same tab. Follow the instructions presented above and use the following scripts:
Method 1 - Bookmarklet
javascript:var linksArr=document.getElementsByTagName("a");for(i=0;i<linksArr.length;i++){linksArr[i].removeAttribute("target");};
Method 2 - Page Actions
function OpenInSameTab() { var linksArr=document.getElementsByTagName("a"); for (i=0;i<linksArr.length;i++) { linksArr[i].removeAttribute("target"); } } if (document.readyState==='complete') { OpenInSameTab(); } else { document.addEventListener('DOMContentLoaded', function() { OpenInSameTab(); }); }
-
@pafflick Is there any way to activate method one with a hotkey on the keyboard?
-
@northmadison There's no way to set up a shortcut to launch a bookmark in Vivaldi, but I believe there are some Chrome extensions that could possibly offer such feature - I found this one for example, but I haven't tested it.
-
We can add a Command Chain
vivaldi://settings/qc/ > COMMAND CHAINS > Chain Name > Open all links from a page in a new tab > Command 1 > Open Link in Current Tab > Command Parameter > javascript:var linksArr=document.getElementsByTagName("a");for(i=0;i<linksArr.length;i++){linksArr[i].setAttribute("target","_blank");};vivaldi://settings/keyboard/ > Chains > Open all links from a page in a new tab
We can also give a Nickname to the bookmark so as to launch / open it with the Quick Commands
We don't need the extension in this case.