Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

html - Button to redirect to another page and automatically pop modal

I have a button on a page (page 2) that links to another page (page 1). On page 1 I have a modal. How would one set the button on page 2 to link to page 1, and automatically pop the modal. I understand a normal link would be href='/page1', I have tried href='/page1#modal', but this does not work. I am running jQuery if this would be the route to go - I have seen some solutions around this but very outdated.

If this is even possible, any help or pointers will be much appreciated.

question from:https://stackoverflow.com/questions/65933219/button-to-redirect-to-another-page-and-automatically-pop-modal

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add #modal part to the href in page2, and check URL on page1 load and if it contains #modal, show modal.

$(document).ready(function(){
  if(window.location.href.indexOf('#modal') > -1)
    $('#myModal').modal();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...