Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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

              
                <div id="explanation">
  <div id="heading">
    <h1>
        This pen grabs the search query from a URL and shows a customized popup based on the search query. 
     </h1>
  </div>
  <p>
    I created this when two companies merged and wanted users clicking on their old site links to be informed of the merge. The old sites were redirected to the new site with a search parameter specific to those sites. 
  </p>
  <p>
    The buttons below add a string query to the current URL. In your build you will simply add that search parameter in your 301 redirect, I am doing it here simply for demonstation. 
  </p>
  <p>
    Click the console tab at the bottom of this pen and you will see the current URL change. 
  </p>
</div>
<div id="flex">
  <div id="addFirstParam">
    Pass First Param
  </div>
  <div id="addSecondParam">
    Pass Second Param
  </div>
</div>
<div id="popup-wrapper">
  <div id="popup">
    <div id ="text">
      <h4></h4>
      <p>We’ve grown to include a host of new services, providing both traditional and digital advertising. You’ll find new inspirations, new faces and the same exceptional service you’ve come to expect.
      </p>
      <div id="close-popup"></div>
     </div>
  </div>
</div>

              
            
!

CSS

              
                body {
  font-family: Arial, Helvetica, sans-serif;
  background-color: #252934;
}
body h4 {
  font-size: 25px;
}
body p {
  font-size: 18px;
  color: white;
}
body h1 {
  color: white;
}
#text p {
  color: black;
  padding-left: 10px;
  padding-right: 10px;
}
#explanation {
  padding-left: 20%;
  padding-right: 20%;
  text-align: center;
}
#explanation p {
  padding-left: 20%;
  padding-right: 20%;
  font-size: 20px;
}
#flex {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}
#flex > div {
  margin: 10px;
}

/* button styles */
#addFirstParam {
  display: flex;
  justify-content: center;
  border: 2px solid black;
  padding: 14px 28px;
  font-size: 16px;
  cursor: pointer;
  border-color: #04C2C9;
  color: #04C2C9;
  min-width: 150px;
}
#addSecondParam {
  display: flex;
  justify-content: center;
  min-width: 150px;
  border: 2px solid black;
  padding: 14px 28px;
  font-size: 16px;
  cursor: pointer;
  border-color: #E31B6D;
  color: #E31B6D;
}

/* popup screen overlay - display none by default */
#popup-wrapper {
  background-color: rgba(0, 0, 0, 0.65);
  position: fixed;
  display: none;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}
#close-popup:after {
 content: 'x';
 font-weight: 300;
 font-family: Arial, sans-serif;
}
#close-popup {
  position: absolute;
  top: 5px;
  right: 15px;
  font-size: 30px;
  font-weight: bold;
}

/* popup model styles */
#popup {
  position: absolute;
  background-color: #fff;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 600px;
  cursor: pointer;
}
#text {
  text-align: center;
  padding-top: 3%;
  padding-bottom: 5%;
  padding-right: 1%;
  padding-left: 1%;
}

/* mobile styles */
@media only screen and (max-width: 1000px) {
  #explanation, #explanation p {
    padding-left: 5px;
    padding-right: 5px;
    font-size: 16px;
  }
  #explanation h1 {
    font-size: 20px;
  }
  
}


              
            
!

JS

              
                // Dynamic popup based on search parameter
const buildModal = (fromParam, style) => {
  const popUp = document.querySelector('#popup-wrapper')
  const popupHeading = document.querySelector("h4")
  const closePopup = document.querySelector("#close-popup")
  // Build popup heading and set style
  popupHeading.style.color = style;
  popupHeading.innerHTML = `Hello, you came from ${fromParam} parameter`
  // Activate popup
  popUp.style.display = "block"
  // Add listener to parent so user can dismiss by clicking anywhere on the modal 
	closePopup.parentNode.onclick = () => { 
  popUp.style.display = "none"
	// Remove query from url
	window.history.pushState({}, document.title, "/");
		}
}

const paramPopup = () => {
	if (window.location.href.includes("First")) {
    buildModal("First","#04C2C9");
	} else if (window.location.href.includes("Second")) { 
    buildModal("Second","#E31B6D");	
	} else {
		console.log("User didn't come from either parameter")
	}
}

//this is the call you would add on your build instead of the buttons
//window.onload = paramPopup(); 








/*BELOW CODE IS FOR THIS DEMONSTRATION, YOU MOST LIKELY WILL NOT BE CHANGING THE URL FROM A BUTTON */

// Button press will change the current url parameter in order for us to grab that parameter with Javascript to trigger the popup. I am doing this for it to work on code pen, on a normal site you would pass the url query via a redirect or something. 


document.querySelector("#addFirstParam").addEventListener("click", () => {
  window.history.pushState({}, document.title, "/" + "?FirstParam");
  console.log(window.location.href)
  paramPopup();
})


document.querySelector("#addSecondParam").addEventListener("click", () => {
  window.history.pushState({}, document.title, "/" + "?SecondParam");
  console.log(window.location.href)
  paramPopup();
})



              
            
!
999px

Console