Only execute a function when specific page go to the page

I am trying to make a popup screen to show up after the page loaded, but the task required only A page moves to B page then the popup showed, if C page or D page can move to B page then the popup won’t show up:

A —> B (popup)

C / D —> B (nothing happened)

may I know are there any ways to perform such thing? Thank you!