cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

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.

            
              <button onclick="showNewtorkInformation();">Show Network Information</button>

<p class="message information"></p>

<p class="message error noAPI">
  You browser does not support <span>navigator.connection</span>
</p>

<p class="message error incompleteAPI">
  You browser has incomplete implementation of <span>navigator.connection</span>. Things like <span>navigator.connection.type</span> and <span>navigator.connection.downlinkMax</span> are used in this demo.
</p>
            
          
!
            
              .message {
  padding: 20px;
  line-height: 2;
  border: 1px solid #f2f2f2;
  display: none;
  
  &.error {
    border: 1px solid #e60000;
    background: #ffb3b3;
    color: #e60000;
  }
  
  a {
    text-decoration: none;
    color: white;
    font-weight: bold;
  }
  
  span {
    border: 1px solid white;
    border-radius: 5px;
    padding: 5px;
    background: #f2f2f2;
  }
}

.show {
  display: block;
}

button {
  display: block;
  width: 50%;
  height: 50px;
  margin: 20px auto;
  background:  #99ff99;
  border: 1px solid #00e600;
  color: #008000;
  cursor: pointer;
}
            
          
!
            
              function showNewtorkInformation() {
  if(!navigator.connection) {
    showMessage('.noAPI');
    return;
  }

  if(!navigator.connection.type || !navigator.connection.downlinkMax) {
    showMessage('.incompleteAPI');
    return;
  }
  
  let text = `
    Connection type as obtained from
    <span>navigator.connection.type</span>
    : ${navigator.connection.type}.
    <br/>
    Connection downlink as obtained from
    <span>navigator.connection.downlinkMax</span>
    : ${navigator.connection.downlinkMax}.
    <br/>
    Connection effective type as obtained from
    <span>navigator.connection.effectiveType</span>
    : ${navigator.connection.effectiveType}.
    <br/>
    Connection RTT as obtained from
    <span>navigator.connection.rtt</span>
    : ${navigator.connection.rtt}.
  `;
   
    document.querySelector('.information')
      .innerHTML = text;
    showMessage('.information');
  
    // Handle Change in type or downlink information
    navigator.connection
      .addEventListener('change', showNewtorkInformation);
}

function showMessage(classname) {
  document.querySelector(classname).classList.add('show');
}
            
          
!
999px
Loading ..................

Console