최근 검색


최근 검색 없음

How can I create a modal in an article that when opened, a different webpage will display in the modal

답변함


2021년 10월 01일에 게시됨

I would like to add a button to a help article that when clicked will open a modal displaying a different webpage while remaining on the original help article. 

The "different webpage" is a subscription page our clients can enter their name and email to subscribe to company updates that we do not house in the Support Center. I know we can just have the button open a new window, but thought it would be fun to do it inside a modal. 

Any help would be appreciated!

 


0

4

댓글 4개

Add this part to your master page. In your page which will have the the control to open the modal, add this div. I am using Link Button to open the modal. This is how you can trigger the javascript function.

/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content/Box */
.modal-content {
  background-color: #fefefe;
  margin: 15% auto; /* 15% from the top and centered */
  padding: 20px;
  border: 1px solid #888;
  width: 80%; /* Could be more or less, depending on screen size */
}

/* The Close Button */
.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}

1


Hi Melody, please follow the below steps to add a modal with another webpage.

1). Go to your article page and paste it at the bottom on the file.

<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>

<!-- The Modal -->
<div id="myModal" class="modal">

<!-- Modal content -->
<div class="modal-content">
<span class="close">&times;</span>
<iframe src="https://URL.zendesk.com/hc/en-us" style="height:200px;width:300px;" title="Iframe Example"></iframe>
</div>

</div>



https://www.w3schools.com/howto/howto_css_modals.asp - add your webpage URL

 

Screenshot for same:

 

2). Open your style.css file and paste it at the bottom.

 

/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}

/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}

.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}

.modal-content iframe{
height: 100vh !important;
width: 100% !important;
}

 

3). Open your script.js file and paste it at the bottom under the DOM function.

// Get the modal
var modal = document.getElementById("myModal");

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}

 

Screenshot for the same:

 

 

Output is:

 

See the button -

 

 

when you are clicked this button- my homepage is open under the modal over current article

 

 

 

 

Put the code from: https://www.w3schools.com/howto/howto_css_modals.asp

Hope it works for you.

Thanks

0


Good morning Ifra Saqlain, this seems to be a good start, thank you! 

A couple of questions:

1. Is it possible to simply insert a modal into an article via the article html, instead of having an entire article template? 

2. I would want this modal only to open when a user clicked a button I put on the article, how do I achieve this?

0


Hi Melody Quinn, I think first create the subscription page as you need with functionality and then wrap the link of the subscription webpage inside the iframe under the modal.

e.g.

<!-- The Modal -->
<div id="myModal" class="modal">

<!-- Modal content -->
<div class="modal-content">
<span class="close">&times;</span>


  <iframe src="URL OF SUBSCRIPTION WEBPAGE" height="200" width="400"></iframe


</div>
</div>

 

 

0


댓글을 남기려면 로그인하세요.

원하는 정보를 못 찾으셨나요?

새 게시물