Robson
Robson

Reputation: 1277

How to run function after reload to another page from special link?

How can I check if I redirected from special link ?

I have two link list:

<ul class="menu">
        <li class="item"><a href="/offer">Offer</a></li>
        <li class="item"><a href="/about">About</a></li>
        <li class="item"><a href="/contact">Contact</a></li>
    </ul>

<ul class="special-menu">
    <li class="item"><a href="/offer">Offer</a></li>
    <li class="item"><a href="/about">About</a></li>
    <li class="item"><a href="/contact">Contact</a></li>
</ul>

I want to know, if I went to for example /offer from ul.special-menu and run specialFunction();

How can I do that in JS ?

Thank everyone in advance.

Upvotes: 3

Views: 69

Answers (1)

Duncan Tidd
Duncan Tidd

Reputation: 1210

I would append a query string onto the urls inside 'special-menu'.

As so: <li class="item"><a href="/offer?qs=specialMenu">Offer</a></li>

Then on the offers page you can get the query string and save it as a variable, then process it how you wish.

var qs = location.search.replace(/^.*?\=/, '');
if (qs === "specialMenu") {
 specialFunction();
}
else {
// do something else
}

Upvotes: 2

Related Questions