Make Player Hold and Hang on the Edge of the Platform

How do I make the player hold and hang on the edges of the platform like the way shown in the classic NES game Aladdin? An image is given below for reference.
hanging