私はこのGoogleChrome拡張機能を持っています。
マニフェスト.json:
{
"name": "My extension",
"manifest_version": 2,
"version": "1.0",
"permissions": [
"tabs", "http://*/*"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["jquery-1.8.3.min.js", "content.js"],
"run_at": "document_end"
}
]
}
popup.html:
<!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>
<div id="ajax">
</div>
</body>
</html>
popup.js:
function start() {
var reg = false;
if (window.ActiveXObject){
reg = new ActiveXObject("Microsoft.XMLHTTP");
}else {
reg = new XMLHttpRequest();
}
reg.open("GET","http://www.dr.dk/",true); // Insert a reference of the php page you wanna get instead of yourpage.php
reg.send(null);
reg.onreadystatechange = function () {
if (reg.readyState == 4 && reg.status == 200) {
document.getElementById('ajax').innerHTML = reg.responseText;
}else {
no_connection();
}
}
}
function no_connection() {
var reg = false;
if (window.ActiveXObject){
reg = new ActiveXObject("Microsoft.XMLHTTP");
}else {
reg = new XMLHttpRequest();
}
reg.open("GET","no_connection.html",true); // Insert a reference of the php page you wanna get instead of yourpage.php
reg.send(null);
reg.onreadystatechange = function () {
if (reg.readyState == 4 && reg.status == 200) {
document.getElementById('ajax').innerHTML = reg.responseText;
}else {
document.getElementById('ajax').innerHTML = 'An Unknown Error did happened.';
}
}
}
start();
これは常にno_connection.htmlのコンテンツを思い付くだけですが、コメントを外すと次の行になります。
no_connection();
から:
function start();
その後、正常に動作し、次のコンテンツが表示されますhttp://www.dr.dk/
がステートメントno_conncection();
内にある場合、これはどのように発生する可能性がありますか?if else
これはかなり奇妙になっているので、この問題を修正する方法のアイデア。