0

I am facing issue with redirect to previous page in community. My current page url is like this

http://communityurl.com/Mysecondpage?id=01p7A123456AmUo

i am passing id value from MyFirstPage. I have tried with following javascript code to redirect to previous page. But it is not working , it is loading and staying on same page.

**<button class="button1" onclick="redirect();"> Back </button>


 function redirect(){
                var url = window.location.href; 
                var value = url.substr(0,url.lastIndexOf('/') + 1);
                value= value+'MyFirstPage';
                console.log(value);
                window.open(value, '_self');
        }**

Please suggest how to redirect to another page , when user clicks on Back button!!

Thanks in advance

3
  • Works fine in my test (albeit using a visual force page not in a community). Do you get any errors in the console? Does the URL look correct?
    – Eric
    Sep 16, 2016 at 1:44
  • Eric, It was working fine in vf page preview mode. When i am checking in community it is showing same page. it is not redirecting to first page . Any permission need to give in community . Please suggest communityurl.com/Mysecondpage?id=01p7A123456AmUo
    – user31113
    Sep 16, 2016 at 3:30
  • I have resolved using this code in communities. Thanks for your suggestions and help.
    – user31113
    Sep 20, 2016 at 10:46

1 Answer 1

1

I have resolved using this code in communities. Thanks for your suggestions and help.

****<button class="button1" onclick="return redirect();"> Back </button>

function redirect(){
                var url = window.location.href; 
                var value = url.substr(0,url.lastIndexOf('/') + 1);
                value= value+'MyFirstPage';
                console.log(value);
                window.open(value, '_self');
               return false;

        }****

We have to write return in javascript , so that it will redirect to another page

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .