SHRX
SHRX

Reputation: 579

Opening a link and trigger modal box on target page?

our customer ordered a simple html one pager website.

the imprint and data protection contents are in the main HTML file and are shown in a modal box.

the modal box is hidden by default and pops up when you click imprint/dataprotection buttons in the footer.

now the customer needed another page and wants to link the imprint and dataprotection there too, but i cant say "open link AND then open modal", right?

is there a possibility to achieve this which i am overlooking?

Upvotes: 1

Views: 77

Answers (1)

Chiel
Chiel

Reputation: 1442

I think I have a solution to your problem. Suppose main.html holds the imprint, data protection and here the modal shows up with the function showModal() (For example). ohter.html then holds the some simple info.

You can "call" the function showModal on main.html by passing a hash (#) with the url and then checking on main.html if that hash is available and then call the function.

It would look something like this:

other.html

some html content...
<a href="/main.html#showModal">See your info</a>
...

main.html

<script>
window.onload = function() {
   if(window.location.hash == "#showModal") {
      showModal();
   }
}
</script>

Hope this gives you an idea of how you could implement such behaviour. If this wasn't of help, please comment.

Upvotes: 2

Related Questions