The loss of Norway is tied into the wider conflict that was the Napoleonic Wars, saying Denmark lost Norway in the Swedish-Norwegian War of 1814, is just as wrong as saying it was lost in the gunboat war.
The loss happened during congress of Vienna, where Denmark accepted to exchange Norway, for Swedish-Pomerrania, which was traded for the duchy of Lauenburg, a smallish state just south of Holstein.
The Swedish-Norwegian War of 1814 Denmark had no hand in, exept for a danish prince being offered the throne of Norway. But the fact is no Danish soldiers fought it the war (to my knowledge) and even if Denmark wanted to participate, they lacked the means to, the navy was gone. and with that the ability to ferry any troops to Norway. Besides while the Danish army had avoided big losses during the war (limited to skirmishes in Holstein) it was a relative well functioning army under relative competent general. Nevertheless I believe bernadotte is a superior general to Prince Frederik of Hesse.
this guy:
https://en.wikipedia.org/wiki/Prince_Frederik_of_Hesse
Anyways the point is by the time of 1814 Norway is lost to Denmark even if it wanted to fight.
The gunboat war is also a wrong place to start (IMO) the strategy and hope of
@Sam Biswas is way too optimistic in my opinion. There is simply no way gunboats can challenge ships of the line, especially not cutting off the British from the kattegat and skagerak, while notorious if the waters are unknown to the captains, it is simply too open. Now if somehow miraculous Denmark(-Norway) can scrap together enough ships of the line and support ships. Maybe but that's even more of a tall order.
I argue if you wanna avoid Denmark(-Norway) loosing the last part of its name, to Sweden in 1814 I think there is two points you can do this.
1) Change the outcome of the Battle of Copenhagen in 1801. (which I think is doable)
2) Avoid Danish entrance into the Napoleonic wars on the French side.
the first scenario can change the dynamics of the great game in northern Europe, and might not lead to the bombardment of Copenhagen a few years later, avoiding Danish entrance on French side.
second do the same.
Norway is basicly lost when Denmark sides with France, while Sweden sided with Britain.