Pen Settings



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


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


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.


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.


                <!-- Player embed code with an id attribute -->
  <video-js id="myPlayerID"
  style="width: 640px; height: 360px;"
<script src=""></script>

<!-- Display the number of video views the user has watched -->
<p>Number of views = <span id="cookieDisplay1"></span></p>


                /* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
body {
  background-color: #111;
  color: #fff;
 * Styles essential to the sample
 * are below


                videojs.getPlayer('myPlayerID').ready(function() {
    // Function to read the browser cookie
    var read_cookie = function (key) {
        var result;
        return (result = new RegExp('(^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? result[2] : null;

    // +++ Read browser cookie +++
    // Initialize variables and read the browser cookie associated with Brightcove video views
    var myPlayer = this,
        videoStart = 0,
        cookie = read_cookie("BC_views");
    //console.log("BC_views cookie: ",cookie);

    // +++ Define custom error message +++
    // Define an error message for when the user has reached the max number of views
        "errors": {
            "-3": {
                "headline": "You've reached your maximum views.",
                "type": "USER_MAX_VIEWS",
                "message": "Please come back tomorrow."

    // Display the cookie value
    // Comment out the next line when using the iframe implementation
    document.getElementById("cookieDisplay1").innerHTML = cookie;
  // +++ Display custom error message +++
    // If the cookie value is greater than or equal to 2, then display the custom error message
    if (cookie != null && cookie >= 2) {
        // Wait for the player to be loaded before displaying the message
        myPlayer.on("loadedmetadata", function () {
          // The dismiss:false property hides the close button when the message is displayed. This keeps the user from closing the error message and playing the video.
              code: '-3',
              dismiss: false

    // +++ Increment the cookie +++
    // Each time the user plays the video, increment the browser cookie"play", function () {
        var d = new Date();
        d.setTime(d.getTime() + (1 * 24 * 60 * 60 * 1000));
        document.cookie = "BC_views=" + cookie + ";expires=" + d.toUTCString();