I want to copy the title of a web page (or what appears within the tab, the part always visible) and paste that text somewhere.
How can I do this in Chrome?
Use a bookmarklet:
javascript:window.prompt("Copy to clipboard: Ctrl+C, Enter",document.title);
Credit for this window.prompt
trick goes to Jarek Milewski. This bookmarklet also works in ANY browser, even Netscape 3, and not just Chrome.
Add a bookmark by hitting CtrlD or clicking on the star on the right end of the address bar.
Copy title.
Click on "Remove".
ctrl+D
(bookmark), ctrl+C
(copy), tab tab tab space
(remove).
This can be achieved through the page source code:
<meta>
and scripts to find <title>
. This answer is much faster: superuser.com/questions/332717/…
The above script has the annoying habit of creating a blank page with the title at the top, in plain text, making you have to go back to the page whose title you wanted to copy. At least in Firefox 24.0.
A far more effective script that keeps you on the page is:
javascript:var%20title=document.title;if(title){var%20re=/(\\|\/|:|\*|\?|\%22|<|>|\|)/gi;title=title.replace(re,'');void(prompt('Page%20Title',%20title));}
javascript:var title=document.title;if(title){var re=/(\\|\/|:|\*|\?|\"|<|>|\|)/gi;title=title.replace(re,'') + "\r\n" + document.location;void(prompt('Page Title', title));}
You can use the Google Chrome extension Copy URL + Title:
Features:
Also available for Opera from https://addons.opera.com/en/extensions/details/copy-url-title/
This bookmarklet copies the title to the clipboard:
javascript:navigator.clipboard.writeText(document.title);
Browser compatibility: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText#browser_compatibility
How to create a bookmarklet
javascript:navigator.clipboard.writeText(document.title);
This bookmarklet copies the page Title to the clipboard with a single click.
javascript:copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
el.select();
document.execCommand('copy');
document.body.removeChild(el);
if (selected) {
document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
};
copyToClipboard(document.title);
An answer inspired by SΛLVΘ's answer, although not identical:
Bookmark that page.
In the list of bookmarks, right click on that bookmark, choose Edit, and you will see the name and the url; by default, the name is the tab's title, unless you modify it
If you need Markdown as the end result, use Chromium Extension Copy Tab Info.
Copy link of active tab in current window as Markdown
? Could you add a default setting, if it set, the press of Copy Tab info
icon not show dropdown, but do what the default setting.
Commented
Mar 10, 2020 at 12:13
This is a one-liner that works for me on Chrome (compared to other solutions here)
javascript:(function(){var t=document.title,e=window.location.href,n=document.createElement("a");n.setAttribute("href",e),n.innerText=t,document.body.appendChild(n);var r=document.createRange(),o=window.getSelection();r.selectNode(n),o.removeAllRanges(),o.addRange(r),document.execCommand("copy"),document.body.removeChild(n)})();
So tabs get copied as: Google
In summary, the code creates a temporary element with the title and URL of the current page, adds it to the document body, selects the element's content, copies it to the clipboard, and then removes the temporary element. This allows you to copy a clickable hyperlink to the clipboard, which you can paste into other applications.
This is the exact same functionality as in Edge, when copying URLs.
One simple way that doesn't require any extras is to drag the small icon to the left of the URL to the Bookmarks bar (use CTR+Shift+B or Command+Shift+B to show/hide it), and then right-click on the new bookmark, pick Edit and copy the title.
You can also drag the icon to a folder or to your desktop. On most systems this will create a bookmark file and set the page title as file name, from where it can be easily copied.
If you drag the page icon into Pages, Word, LibreOffice, Notes, etc on OSX this will insert a link with the page title as text and the URL as link target. On Windows and Linux just the plain text URL will be inserted, so it is not as handy, but can still be useful.
For example, the page icon from this SO page can be dragged directly into the reply edit form. Selecting the URL in the address bar and dragging it to an editable field usually has the same effect, and this is the alternative on OSX for example when you want the actual URL to be inserted instead of the linked title in a richtext edit.
Here's a bookmarklet that copies the title + url in markdown format
javascript:var title=document.title;if(title){var re= /(\\|\/|:|\*|\?|\"|<|>|\|)/gi;title="[" + title.replace(re,%27%27) + "]("+ document.location + ")";void(prompt(%27Page Title%27, title));}
There is an extension for it. Copy URL To Clipboard - Chrome Web Store
Building on the javascript mentioned by bugz above
( javascript:navigator.clipboard.writeText(document.title);
)
... use the following one in order to preserve the URL in the address field:
javascript:navigator.clipboard.writeText(document.title);history.replaceState({},"",location.href);