/    Sign up×
Community /Pin to ProfileBookmark

Multiple actions on click – ordering issue

Hi!

When the user clicks on a link to a subpage, I want to store data in sessionStorage from the current page before leaving to the next page. Then when this new page has loaded, I want to apply the sessionStorage data on this page.

What complicates things is that the link is part a collapsing menu system. Which means that this system needs to update (which is also done on click) before the page data is stored.

So essentially, the wanted execution order:

>

User clicks link
> Menu system is updated
> Page data is stored
> Browser loads the new page
> Page data from the previous page loads and applies on the new page

My issue is the order in which everything is executed. I don’t understand when the user clicks on the link how to control the order of when the actions are executed.

Thankful for help

to post a comment
HTMLJavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumFeb 26.2020 — AFAIK when a link is clicked, custom event listeners added by javascript are executed first, then the default action is taken, in case of a link loading the new page.

The easiest way to control the order of custom actions is to add only one eventlistener and execute the necessary actions there. In case they are complex you are free to place them inside of functions in order to keep things clear.
×

Success!

Help @Slemnils spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...