If it's got a metal frame, it's a CJ hardtop. It will fit the YJ, but the liftgate will interfere with the spare. I'm pretty sure the YJ hardtop had a frameless rear glass, and it's not interchangeable.
www.4wd.com sells a fiberglass replacement, used to be around $120. That's what I did on my CJ, ended the rust problem forever.