Chrome Extension : Get Current tab
link of last tutorial : Create a Chrome extension in visual studio
In this tutorial we will use chrome.tabs methods.
in the manifest file add a tab permission
"permissions": [
"tabs"
],
In the popup.html file, paste the code bellow
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
min-width: 357px;
overflow-x: hidden;
}
</style>
<script src="jquery.js"></script>
<script src="popup.js"></script>
</head>
<body>
<div id="host"></div>
</body>
</html>
In the popup.js file, paste the code bellow
$(document).ready(function () {
chrome.tabs.getSelected(null, function (tab) {
var link = document.createElement('a');
link.href = tab.url;
$('#host').html("Host : "+link.hostname);
})
});
Enjoy watching