1
구글 크롬 확장에 자바 스크립트에 아이를 추가, 난 그냥이 내 html 파일 소스입니다 here내가 구글 크롬의 확장을 만들기 위해 처음으로 프로그램을 쓰고 있어요
에서 예로서 「Hello World」의 튜토리얼을했다 코드 :
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
min-width:357px;
overflow-x:hidden;
}
img {
margin:5px;
border:2px solid black;
vertical-align:middle;
width:75px;
height:75px;
}
</style>
<!-- JavaScript and HTML must be in separate files for security. -->
<script src="popup.js"></script>
</head>
<body>
</body>
</html>
광고이 내 자바 스크립트 파일의 소스 코드 :
var req = new XMLHttpRequest();
req.open(
"GET",
"http://api.flickr.com/services/rest/?" +
"method=flickr.photos.search&" +
"api_key=90485e931f687a9b9c2a66bf58a3861a&" +
"text=hello%20world&" +
"safe_search=1&" + // 1 is "safe"
"content_type=1&" + // 1 is "photos only"
"sort=relevance&" + // another good one is "interestingness-desc"
"per_page=20",
true);
req.onload = showPhotos;
req.send(null);
function showPhotos() {
var photos = req.responseXML.getElementsByTagName("photo");
var element = document.createElement('h1');
element.appendChild(document.createTextNode
('tete '+document.location.href+'hgdfhgd'));
for (var i = 0, photo; photo = photos[i]; i++) {
var img = document.createElement("image");
img.src = constructImageURL(photo);
document.body.appendChild(img);
}
}
// See: http://www.flickr.com/services/api/misc.urls.html
function constructImageURL(photo) {
return "http://farm" + photo.getAttribute("farm") +
".static.flickr.com/" + photo.getAttribute("server") +
"/" + photo.getAttribute("id") +
"_" + photo.getAttribute("secret") +
"_s.jpg";
}
이 예는 매우 간단하고 잘 작동하지만 내 자신의 자바 스크립트 INSTRU를 추가 할 때 ction은, 그것을 표시되지 않습니다, 추가 된 명령은() 함수 showPhotos이고 그건 :
결과에var element = document.createElement('h1');
element.appendChild(document.createTextNode
('tete '+document.location.href+'hgdfhgd'));
, 내가 다른 콘텐츠를 볼 수 있지만 내 'H1은'나는 그것을 볼 수 없습니다 . 내가 놓친 것이 있습니까? 누구든지 제발 도와 주실 래요?
감사합니다.