การเปิดหน้าแสดงในโมดอลพร้อมอัปเดต URL ในแถบที่อยู่โดยใช้ HTML และ JS

ฉันต้องการรับรหัสของการคลิกปุ่มในแถบที่อยู่เพื่อนำข้อมูลที่เกี่ยวข้องจากฐานข้อมูลเหมือนกับที่ Instagram ทำ ฉันต้องการรับรหัสจากแถบที่อยู่โดยใช้ php เพื่อค้นหาข้อมูลเฉพาะจากฐานข้อมูลตามรหัสของข้อมูลอ้างอิงที่เลือก

หมายเหตุ รูปภาพด้านล่างเป็นเครดิตของ @designer จากโพสต์ คำถาม Stackoverflow ป้อนคำอธิบายรูปภาพที่นี่

ข้อมูลโค้ดของฉันคือ:

<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet"/>


<a    class="btn btn-primary btnModal"  data-target ="#scrapModal"  href="/thwashingPlan.php#scrapModal?id=' . $row['id'] . '" data-toggle="modal" >Service Include</a>


<div class="modal fade bd-example-modal-lg" id="scrapModal" tabindex="-1" role="dialog" aria-labelledby="scrapModal" aria-hidden="true">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">


                        <!-- DataTales Example -->
                        <div class="card shadow mb-4">
                            <div class="card-header py-3">
                                <h6 class="m-0 font-weight-bold text-primary">WASHING PLAN SERVICES</h6>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                
                                    <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                                    <input type="text" name="id" id="id" />

                                        <thead>
                                            <tr>
                                                <th>S.No.</th>
                                                <th>Washing plan Services</th>
                                                <th>Action</th>

                                            </tr>
                                        </thead>
                                        <tfoot>
                                            <tr>
                                                <th>S.No.</th>
                                                <th>Washing plan Services</th>
                                                <th>Action</th>
                                            </tr>
                                        </tfoot>
                                        <tbody>


                                        


        <tr>
        <th>test</th>
        <th>test1</th>
        <th>test2</th>
    </tr>

                                        
                                            
                                   
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <form action="" method="post">

                            <div class="col-lg-8 m-4">
                                <label class="ml-1">Plans Include</label><br>
                                <input type="text" id="plans" name="plans" placeholder="" class="col-12" required>
                            </div>

                            <div class="row m-5">
                                <input type="submit" value="Reset" class="btn" style="background-color: #FF9933;letter-spacing: 0.6px;border-radius: 2px;color: #FFF;">
                                <input type="submit" class="btn" name="includeService" value="Add Value" style="background-color: #0891FF;;letter-spacing: 0.6px;border-radius: 2px;color: #FFF; display: inline-block;vertical-align: middle;">
                            </div>
                        </form>


                    </div>
                </div>
            </div>

ที่อยู่ไม่เปลี่ยนแปลงเมื่อฉันเพิ่ม data-target=modal มีเทคนิคการทำโมดอลแบบนี้มั้ย?

ขอบคุณล่วงหน้า


person Muhammad Addan Sarfraz    schedule 26.07.2020    source แหล่งที่มา


คำตอบ (1)


ฉันว่าคุณกำลังมองหา History API ซึ่งช่วยให้คุณจัดการประวัติเบราว์เซอร์ (รวมถึงแถบ URL) โดยใช้ JS

history.pushState() อนุญาตให้คุณ 'เพิ่ม' เพจไปที่ สแต็กประวัติซึ่งจะเปลี่ยน URL เป็นสิ่งที่คุณระบุ

หากคุณฟังเหตุการณ์ window.onpopstate คุณสามารถ ตรวจจับเมื่อผู้ใช้นำทางประวัติโดยใช้การควบคุมเบราว์เซอร์ (เช่นปุ่มย้อนกลับ) ขัดจังหวะและจัดการด้วยตนเอง ทั้งหมดนี้โดยไม่ต้องโหลดหน้าซ้ำ!

นั่นน่าจะเพียงพอสำหรับการเริ่มต้น เนื่องจากเป็น API ที่มีประโยชน์มากในการใช้ประโยชน์

person Tom Anderson    schedule 26.07.2020