Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How do I make it so that the webpage changes to another page when the user tries to close the window or tab?

I've seen this before in my study of marketing and sales funnel. The idea is that if the potential customer tries to exit out of a video sales page, they will see the text sales page pop up instead.

I have no idea where to begin with this coding-wise tho, and having trouble googling it. I'm guessing it has something to do with javascript but if I'm wrong then sorry for putting this in the wrong category.

Can anybody point me in the right direction?

2 Answers

Thanks Dustin

No problem. :smiley:

Hey Shams, while this is certainly possible, I don't think this sort of technique is recommended for the best user experience. Modern web marketing has changed a lot since these methods. You'll still see it out there, but it will most likely frustrate and push the user away from making a potential sale.

However, I think you're most likely referring to dark patterns, which I don't believe will provide any long-term business success.

Hey, thanks for the info! I'll be sure to share it with my boss. Still, for the time being I should figure out how to do this anyways... so if anyone has any links or can give me a clue on how this is done then please let me know!