나는 크롬 확장에서 URL을 열기 위해 간단한 자바 스크립트를 실행 해야하는 Google 크롬 확장을 만들려고합니다 앵커 태그가 그렇게 할 수 있다는 것을 알고 있지만 다른 기능을 js에 추가하고 싶었습니다.
javascript가 실행될 간단한 pop.html 파일은 다음과 같습니다.
<html>
<body>
<form>
<div id="search_panel">
<input type="text" id="box" name="txt" required placeholder="Search anything"/> <input type="submit" id="stu_submit" onclick="hey();" name="stu_post" value="Search"/>
<div> <a href="http//s.com" target="_blank" id="stu_links" >s.com</a> <a href="#" id="stu_links">news</a> <a href="#" id="stu_links">hey</a> <a href="#" id="stu_links">Sign In</a> </div>
</div>
<script>
function hey()
{
window.open('http://www.google.com');
}
</script>
</form>
</body>
</html>
매니페스트 파일은 다음과 같습니다.
{
"name": "Chrome Extension for s.com",
"version": "1.0",
"manifest_version": 2,
"description": "Google Chrome Extension for s.com.",
"browser_action":
{
"default_icon": "img/icon.png",
"default_menu": "FirstMenu",
"default_popup": "popup.html"
},
"chrome_url_overrides" : {
"newtab": "s.html"
},
"permissions": [
"http://api.flickr.com/"
]
}
popup.html에서 js를 실행하는 방법을 도와주세요.
도움이 될 수 있습니다. Chrome 확장 프로그램에서 자바 스크립트 실행-> 기본?
빠른 참조를 위해 여기에 복사했습니다.
크롬 확장 문서에 따르면
인라인 JavaScript는 실행되지 않습니다. 이 제한은 인라인 <script>
블록과 인라인 이벤트 핸들러 (예 :)를 모두 금지합니다 <button onclick="...">
.
읽기 : http://developer.chrome.com/extensions/contentSecurityPolicy.html#JSExecution
popup.js에서 다음과 같이 사용하십시오.
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('button').addEventListener('click', main);
});
function main() {
var source = document.getElementById('source').value;
document.getElementById("result").innerHTML = source;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다