Skip to content

Instantly share code, notes, and snippets.

@SolinariWu
Last active May 26, 2017 05:34
Chrome Extension Easy Sample
{
"manifest_version": 2,
"name": "Google extensions easy sample",
"description": "Show current page URL",
"version": "1.0",
"browser_action": {
"default_icon":"icon.png" ,
"default_popup": "popup.html"
},
"permissions": ["tabs"]
}
/*
File:popup.css
Author:SolinariWu
Descript:Google Extensions Easy Sample-Show current page URL
Date:2016/7/25
Reference:https://developer.chrome.com/extensions
http://www.cnblogs.com/guogangj/p/3235703.html
*/
body {
width: 200px;
}
<!--
File:popup.html
Author:SolinariWu
Descript:Google Extensions Easy Sample-Show current page URL
Date:2016/7/25
Reference:https://developer.chrome.com/extensions
http://www.cnblogs.com/guogangj/p/3235703.html
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Google Extensions Easy Sample</title>
<link rel="stylesheet" type="text/css" href="popup.css" />
</head>
<body>
<div id = "msgLabel" ">Show URL</div>
</body>
<script src="jquery-3.1.0.min.js"></script>
<script src="popup.js"></script>
</html>
/*
File:popup.html
Author:SolinariWu
Descript:Google Extensions Easy Sample-Show current page URL
Date:2016/7/25
Reference:http://www.cnblogs.com/guogangj/p/3235703.html
https://developer.chrome.com/extensions
*/
document.addEventListener('DOMContentLoaded', function () {
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var url = tabs[0].url;
$("#msgLabel").text(url);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment