0

This thing is happening only in using in mobile. e.g www.example.com&m=0

I’m using a script to redirect my all links to a particular page which is a confirmation page, where user when click on ‘confirm’ then only they get redirected. www.santhaledisom.com/p/confirmation.html?=‘www.yourcontent.com’ They are redirected to www.mycontent.com only after clicking on ‘confirm’ button.

But it actual appears to be ‘www.mycontent.com&m=0’ and as a result link doesn’t work

This thing is working on fine on desktop version but not in while using in mobile. My site is based on Blogger platform, even when blogger’s mobile template is switched off it still happens same.

Confirmation.html page has button (Id=myButton)

    <script>
   //get a reference to the element 
    var myBtn = document.getElementById('myButton'); 
    var href = document.location.href; 
    var link = href.split('?=')[1]; 
    //add event listener 
    myBtn.addEventListener('click', function(event)
    { 
    window.location.href="http://" link; });

</script>

I guess this might be the thing that switches between mobile and desktop version And add ‘m=0’ to my all url.

 var curl = window.location.href;if (curl.indexOf('m=1') != -1) {curl = curl.replace('m=1', 'm=0');window.location.href = curl;
Shaym Murmu
  • 3
  • 1
  • 7
  • 1
    your second code is not complete, please provide the whole code. – Julian Paolo Dayag Aug 08 '18 at 08:33
  • This is what i found – Shaym Murmu Aug 08 '18 at 08:35
  • I added an answer. – Julian Paolo Dayag Aug 08 '18 at 08:38
  • If you parse the querystring properly (ie the bit after the ? in the url) then you shouldn't have this problem. I notice that you don't seem to have a name for your url parameter, if you did (eg the url was `www.santhaledisom.com/p/confirmation.html?link=www.yourcontent.com` that would then become `www.santhaledisom.com/p/confirmation.html?link=www.yourcontent.com&m=0` and when you got the `link` parameter from the querystring you would still get the right url, no matter how many more querystring elements were added to the url. – Chris Aug 08 '18 at 08:44
  • Thanks@JulianPaoloDayag Is there anyway to make exception ? like if i want this to happen to confirmation page only . – Shaym Murmu Aug 08 '18 at 08:45
  • @Chris Thanks , I didn't think of it, wow. Can you please give me a example ? – Shaym Murmu Aug 08 '18 at 08:54
  • @ShaymMurmu: No, but fortunately google and stack exchange have you covered: https://stackoverflow.com/questions/150404/what-is-the-easiest-way-to-read-manipulate-query-string-params-using-javascript (googled "manipulating querystring in javascript"). – Chris Aug 08 '18 at 08:56
  • 1
    @Chris Thanks , I got it. My problem is solved. – Shaym Murmu Aug 08 '18 at 09:00

2 Answers2

0

Replace the m=0 with just empty string.

var curl = window.location.href;
if (curl.indexOf('m=1') != -1) {
  curl = curl.replace('m=1', '');
  window.location.href = curl;
}
Julian Paolo Dayag
  • 3,562
  • 3
  • 20
  • 32
0

First of all, you cannot remove m=1 or m=0 from link in mobile, it's an obligatory on all blogger blogspots.

your redirect link should has a name for query, you should change your redirect link in prefix script from ?='www.yourcontent.com' to something like that ?link=www.yourcontent.com.

now if you have a link like that: /p/confirmation.html?link=www.yourcontent.com&m=0, you can easily extract target link and you don't need to remove m=1 or m=0, use these simple lines of code:

var myBtn = document.getElementById('myButton'),
    TargetLink;

location.search.substring(1).split('&').forEach(function(par){
    var query = par.split('=');
    if(query[0]==='link'){ TargetLink = query[1] }
});

myBtn.addEventListener('click', function(){
    window.location.href = location.search ? 'http://' + TargetLink : '#';
});
Muhammad Saleh
  • 792
  • 1
  • 6
  • 15
  • Thanks@Muhammad Saleh, It worked as a charm, you helped stackoverflow proven once again for the rest for the world of developers. – Shaym Murmu Aug 08 '18 at 12:46