OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Create a back button that skips specific page

  • Thread starter Thread starter LBF
  • Start date Start date
L

LBF

Guest
I need to add a "Back" link that goes back 1 page (history.go(-1)) UNLESS the previous page is a specific URL. In that case, I want the link to go back 3 pages (history.go(-3)).

I thought this would be simple by using either document.referrer in JS or $_SERVER['HTTP_REFERER'] in PHP, but in both methods, the referring url is always blank, so obviously that won't work.

The referring url that I want to skip would contain the following parameter at the end: ?um_action=edit

So for example, a user might take this path:

  1. mysite.com/directory
  2. mysite.com/member/profile
  3. mysite.com/member/profile/?um_action=edit
  4. mysite.com/member/profile

If you are on step 1, 2 or 3, the back link would take you back to the previous page. But if you are on step 4, I want the back link to jump back to step 1.

How can I achieve this? This is a wordpress site, and there is an action I can hook into that runs on step 3 above when the profile is saved. Could I use this somehow?

Thank you!

<p>I need to add a "Back" link that goes back 1 page (<code>history.go(-1)</code>) UNLESS the previous page is a specific URL. In that case, I want the link to go back 3 pages (<code>history.go(-3)</code>).</p>
<p>I thought this would be simple by using either <code>document.referrer</code> in JS or <code>$_SERVER['HTTP_REFERER']</code> in PHP, but in both methods, the referring url is always blank, so obviously that won't work.</p>
<p>The referring url that I want to skip would contain the following parameter at the end: <code>?um_action=edit</code></p>
<p>So for example, a user might take this path:</p>
<ol>
<li>mysite.com/directory</li>
<li>mysite.com/member/profile</li>
<li>mysite.com/member/profile/?um_action=edit</li>
<li>mysite.com/member/profile</li>
</ol>
<p>If you are on step 1, 2 or 3, the back link would take you back to the previous page. But if you are on step 4, I want the back link to jump back to step 1.</p>
<p>How can I achieve this? This is a wordpress site, and there is an action I can hook into that runs on step 3 above when the profile is saved. Could I use this somehow?</p>
<p>Thank you!</p>
 

Latest posts

Top