If we are in the key of C major and we are going to the IV chord (Fmaj7), we can give weight to F by playing the V chord of Fmaj en route. This move will temporarily shift the key center to F major. The V of Fmaj7 is C7. The C7 chord is a primary dominant in the key of F, and a secondary dominant in the key of C. If we play:
Cmaj7/ C7/ Fmaj7
In the key of C major: C is the Primary key, but F is functioning as the tonic of a secondary key. In this secondary key, C7 is the V chord -- C7 is functioning as a secondary dominant.
Play these chord and listen to the effect. Even though C is the tonic of our key, when we get to Fmaj7, we feel a release of the tension created by the C7 chord. This is because the V chord strongly builds tension pointing to its respective I chord. The flat 7 of C7 (Bb) is outside the key of C. But the chord of C7 resolves nicely when we hit Fmaj7.
A secondary dominant can occur on any chord in a major or minor progression -- except the vii chord, which has no natural V. You could have a secondary dominant for the vi chord. The vi of C is Amin7. In going from Cmaj7 to A-7, we can stick a chord in there that will make it more interesting -- a secondary dominant. The V of A-7 is E7 (E-G#-B-D). Traveling from Cmaj7 to E7 and then to A-7 gives an added tension/release via the secondary dominant.
The same concept would apply to a minor progression. In the key of A minor, if we move to the IV chord (D7) we can preceed the D7 chord with the secondary dominant of A7. The fifth of D is A. So A-7/A7/D7 uses A7 as a secondary dominant which temporarily moves the key center to D7, leading us to D. D is still in the key of A minor, so when we move back to A-7, we will feel A as being the tonic. D was only a secondary tonic that we felt for a split-second, because A7 was functioning as a secondary dominant, demanding resolution to D.
When secondary dominants are 'functioning' dominants, they can be altered with extensions. There are some 'rules' for what extensions work best, but your ear should be your best guide.