I put the one from my old CJ7 on a YJ. The only real issue was the YJ spare tire on the tailgate and wiggling to get the glass past it to open and close. I think the CJ glass might also have blocked the YJ gate from opening such that they had to be opened together.
This was like a dozen years ago and my memory is a bit foggy but the answer is yes it can work.