hi there,
I need help on replacing url parameter, I am using Zeroclipboard script on my page. When someone click on any coupon code then a new window open with the same page and code can be copied from popup. I have these codes on my page :
<div class="btn btn-primary" id="coupon_code_container_<?php echo $couponvalue['id'];?>" >
<strong code="<?php echo $couponvalue['id'];?>" id="coupon_code_<?php echo $couponvalue['id'];?>" data-clipboard-text="<?php echo $couponvalue['couponcode'];?>" class="copyCoupon">GET COUPON CODE</strong>
</div>
AND this java script :
<script type="text/javascript">
$('strong').click(function(){
var join = location.href.match(/\?/)?'&':'?';
var newtab = window.open(location.href +join+'code='+this.getAttribute('code'),'_blank');
//var newtab = window.open(location.href +'#'+this.getAttribute('code'),'_blank');
window.location.href = "/opensite.php?store="+this.getAttribute('code');
newtab.focus();
});
var code = /code=(\d+)/.exec(window.location.search)[1];
if (code){
coupon_code = $('strong[code='+code+']').attr('data-clipboard-text');
$('strong[code='+code+']').html(coupon_code);
$('#myModal').modal('show');
$('#myModal #coupon_code').val(coupon_code);
$('#myModal .copy_coupon').attr('data-clipboard-text',coupon_code);
var client = new ZeroClipboard($('.copy_coupon'));
client.on( "aftercopy", function( event ) {
$('#myModal .copy_coupon').html('COUPON COPIED');
});
}
</script>
My page use pagination like : mysite.com/fasion.html?orderby=id&start=8
Now my problem :
When i go mysite.com/fasion.html and click any coupon code then it opens in new tab and URL of new window is mysite.com/fasion.html?code=123
BUT when i click any coupon on mysite.com/fasion.html?code=123, a new window opens the and now new window URL is now mysite.com/fasion.html?code=123&code=123 and so on....
Same happening if i do it on paginated page like mysite.com/fasion.html?orderby=id&start=8&code=123
and mysite.com/fasion.html?orderby=id&start=8&code=123&code=456 and so on...
What i want : code=123 should be replaced with new one. I can guess but can not figure it out here :
var join = location.href.match(/\?/)?'&':'?';
var newtab = window.open(location.href +join+'code='+this.getAttribute('code'),'_blank');
//var newtab = window.open(location.href +'#'+this.getAttribute('code'),'_blank');
problem can be seen here : catchcoupons dot in/category/Fashion-and-Accessories.html