0
Я делаю расширение chrome, которое при нажатии кнопки получает текущий url и значение в поле ввода.Ошибка при попытке получить значение элемента формы в расширении chrome
Но я получаю сообщение об ошибке:
Uncaught TypeError: Cannot read property 'value' of null at HTMLButtonElement.myAlert
в строке:
var ip = document.getElementById('ip_dns').value;
Как это правильный путь, чтобы получить и сохранить это значение?
Вот мой код:
popup.html
<!doctype html>
<html>
<head>
<title>DNS Teste</title>
<script src="popup.js"></script>
</head>
<body>
<form>
IP DNS
<input type="text" ip="ip_dns">
<button id="btn">Teste</button>
</form>
</body>
</html>
popup.js
function myAlert(){
chrome.tabs.getSelected(null, function(tab) {
var url = tab.url;
console.log("url: "+ url);
});
var ip = document.getElementById('ip_dns').value;
console.log("IP: "+ip);
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('btn').addEventListener('click', myAlert);
});
manifest.json
{
"manifest_version": 2,
"name": "Getting started example",
"description": "This extension shows a Google Image search result for the current page",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/",
"tabs"
]
}
Вы опечатка здесь: <входной тип = "текст" IP = "ip_dns">, может быть, это вопрос? измените его на –