Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <p>此页面会自动检测您是否能正常访问 Google, Disqus, YouTube, Twitter, Facebook, 百度 与 DuckDuckGo。</p>

<button id="checkBtn" onclick="check();">立即检测</button>

<div id="result"></div>
              
            
!

CSS

              
                body {
  text-align: center;
  font-family: SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;
  font-size: 1rem;
}


#result {
  background-color: #f2f5f8;
  padding: 10px;
  margin: 10px;
}

#result .error {
  color: #d9534f;
}

#result .ok {
  color: #42b983;
}
#checkBtn {
    color: #fff;
    background-color: #007bff;
    border-color: #007bff;
    cursor: pointer;
    text-align: center;
    vertical-align: middle;
    user-select: none;
    border: 1px solid transparent;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
              
            
!

JS

              
                function check() {
  document.querySelector("#result").innerHTML = "";
  for (var i = 0; i < checkList.length; i++) {
    checkSite(checkList[i]);
  }
}

checkList = ['google.com','disqus.com','youtube.com','twitter.com','facebook.com','baidu.com','duckduckgo.com']

function checkSite (url) {
  // 新建一个图片
  var img = new Image();
  // 设置图片的链接
  img.src = "https://"+url+"/favicon.ico";

  // 设定超时事件,延迟 3000 毫秒
  var timeout = setTimeout(function () {
      // 清除 onerror 和 onload 事件
      img.onerror = img.onload = null;
      console.log("time out.");
      // 执行无法加载的事件
      canNotLoad();
  },3000);

  // 设定错误事件
  img.onerror = function () {
      // 先清除超时事件
      clearTimeout(timeout);
      console.log("load error.");
      // 执行无法加载的事件
      canNotLoad();
  }

  // 设定可以加载的事件
  img.onload = function () {
      // 先清除超时事件
      clearTimeout(timeout);
      console.log("ok.");
      // 执行可以加载的事件
      canLoad();
  }

  function canNotLoad() {
    /* code here */
      canNotLoadSite(url);
  }
  function canLoad() {
    /* code here */
      canLoadSite(url);
  }
}


function canNotLoadSite(url) {
  var t = document.createElement("p");
  t.innerHTML = `<span class="error">${url}</span>`;
  document.querySelector("#result").appendChild(t);
}

function canLoadSite(url) {
  var t = document.createElement("p");
  t.innerHTML = `<span class="ok">${url}</span>`;
  document.querySelector("#result").appendChild(t);
}
              
            
!
999px

Console