简体   繁体   English

单击href链接时如何将查询字符串参数添加到相同的URL

[英]how to add query string parameter to same URL when on click a href link

 //script to show magnific popup <script> $('.gallery-lb').each(function() { // the containers for all your galleries $(this).magnificPopup({ delegate: 'a', // the selector for gallery item type: 'image', gallery: { enabled:true }, mainClass: 'mfp-fade' }); }); </script> //script to show popup (function ($) { [ Show modal1 ]*/ $('.js-show-modal1').on('click',function(e){ e.preventDefault(); $('.js-modal1').addClass('show-modal1'); }); $('.js-hide-modal1').on('click',function(){ $('.js-modal1').removeClass('show-modal1'); }); })(jQuery); 
 <?php //Quick View link at index.php page if(count($product) > 0) { foreach ($product as $products){ echo' <a href="?qid='.$products['Product_ID'].'" class="block2-btn flex-cm stext-103 cl2 size-102 bg0 bor2 hov-btn1 p-lr-15 trans-04 js-show-modal1">Quick View </a> ';}?> <!-- Display product details on magnific modal popup --> <div class="wrap-modal1 js-modal1 pt-60 pb-20"> <div class="overlay-modal1 js-hide-modal1"></div> <div class="container"> <div class="row"> <div class="slick3 gallery-lb"> <?php //check if query string exist in URL if(isset($_GET['qid']) && !empty($_GET['qid'])){ //get selected product details from database and display at magnific modal popup $selectedproduct =$app->getProductDetails($_GET['qid']); if(count($selectedproduct) > 0){ foreach ($selectedproduct as $productdetail){ echo ' <div class="item-slick3" data-thumb="'.$productdetail['Product_Image'].'"> <div class="wrap-pic-w pos-relative"> <img src="'.$productdetail['Product_Image'].'" alt="IMG-PRODUCT"> <a class="flex-cm size-108 how-pos1 bor0 fs-16 cl10 bg0 hov-btn3 trans-04" href="'.$productdetail['Product_Image'].'"> <i class="fa fa-expand"></i></a> </div> </div> <div class="item-slick3" data-thumb="'.$productdetail['Product_Detail_Image01'].'"> <div class="wrap-pic-w pos-relative"> <img src="'.$productdetail['Product_Detail_Image01'].'" alt="IMG-PRODUCT"> <a class="flex-cm size-108 how-pos1 bor0 fs-16 cl10 bg0 hov-btn3 trans-04" href="'.$productdetail['Product_Detail_Image01'].'"><i class="fa fa-expand"></i></a> </div> </div> <div class="item-slick3" data-thumb="'.$productdetail['Product_Detail_Image02'].'"> <div class="wrap-pic-w pos-relative"> <img src="'.$productdetail['Product_Detail_Image02'].'" alt="IMG-PRODUCT"> <a class="flex-cm size-108 how-pos1 bor0 fs-16 cl10 bg0 hov-btn3 trans-04" href="'.$productdetail['Product_Detail_Image02'].'"> <i class="fa fa-expand"></i></a> </div> </div>'; } } }?> </div> </div> </div> </div> 

I wanted to created an ecommerce site that displays product details in a lightbox popup when user clicks on a "Quick View" link of a particular product. 我想创建一个电子商务网站,当用户单击特定产品的“快速查看”链接时,该网站在灯箱弹出窗口中显示产品详细信息。 However, I'm unable to do so as the query string that is appended on the product "Quick View" link is not shown on the index URL when the onclick action is performed. 但是,我无法这样做,因为执行onclick操作时,附加在产品“快速查看”链接上的查询字符串不会显示在索引URL上。 Hence, lightbox display empty result after clicking on the product link. 因此,点击产品链接后,灯箱将显示空白结果。

Product Quick View URL looks something like this: http://localhost/index.php?qid=(some product ID). 产品快速查看URL看起来像这样: http://localhost/index.php?qid =(某些产品ID)。

I am using magnific popup source code to display lightbox. 我正在使用巨大的弹出源代码来显示灯箱。

Expected result: Upon clicking the product quick view link, a lightbox will popup to show product details of the selected product in the index URL page. 预期结果:单击产品快速查看链接后,将弹出一个灯箱,以在索引URL页面中显示所选产品的产品详细信息。

How can I add query string to the index URL when onclick a href link so that appropriate product details can be fetch from database based on the query string qid (aka product id) and displayed at lightbox. 当我单击href链接时,如何将查询字符串添加到索引URL,以便可以基于查询字符串qid(即产品ID)从数据库中获取适当的产品详细信息,并显示在灯箱中。 Would appreciate someone to help me with this. 希望有人帮助我。 :) :)

Something like this 像这样

 <a onclick="window.location='http://localhost/index.php'+window.location.search;">Quick View</a> 

maybe? 也许?

We don't need that much of code for this, if you just want to add something to the url. 如果您只想在url中添加一些内容,则不需要太多代码。 you can just use .pushState function on javascript. 您可以只在javascript上使用.pushState函数。

history.pushState({}, "page title", "?qid=some_product_id or anything");

Find details here: https://developer.mozilla.org/en-US/docs/Web/API/History_API#Adding_and_modifying_history_entries 在此处查找详细信息: https : //developer.mozilla.org/zh-CN/docs/Web/API/History_API#Adding_and_modifying_history_entries

this will also presist history. 这也将保留历史。

You can use following code and add parameters to query string 您可以使用以下代码并向查询字符串添加参数

window.history.replaceState(null, null, "?param1=value"); window.history.replaceState(null,null,“?param1 = value”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击时将Query-String参数添加到静态链接 - Add Query-String parameter to static link on click 单击标签a时如何向href URL添加参数? - How can add parameters to href url when click on tag a? jQuery-如何在单击链接后重定向到上一页并在URL中添加属性href? - Jquery - How to redirect to previous page and add attribute href in url after click on link? 在AngularJS中单击具有相同URL的链接时如何捕获事件? - How to catch event when click on link with the same url in AngularJS? 如何在具有#as href且在表单内提交的链接上更改URL参数 - How to change a URL parameter on a link that has # as href and is submitted inside a form 如何添加/更新查询字符串链接到现有URL的末尾 - How to add/update query string link to end of exisiting URL 单击“ a href”时如何添加预加载器? - How to add a preloader when you click on a “a href”? 如何在href链接上使用js参数和锚点(同一页面) - How to use js parameter and anchor(same page) on a href link <a>单击指向外部站点的链接时,</a>如何将当前 url 参数添加到 an 的 href - How can I add the current url parameters to the href of an <a> when clicking link to external site 如何在 Jquery 数据表中添加带有参数的 href 调用 javascript function 链接? - How to add link with href calling javascript function with parameter in Jquery datatables?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM