简体   繁体   中英

Hide a form based on referer_url value

I have a small form on my 404 page that I only want to be shown if the visitor comes from a website -- thus if a visitor comes from an email link or directly accesses the URL, then I don't want them to see the form at all.

The reason: this form is about a broken link they have clicked to get to this 404 web page. If they clicked on an email link, or if they just typed the URL, then there's nothing I can correct. So there's no need for a form. But if they arrived from a link (on the same site or another site), then I want the form to show.

I do understand that I may have to use the Javascript referer_url option, but is there any way to hide the form if the visitor has no referer_url value?

Thank you so much.

It should be pretty straight forward, if document.referrer has a value show, otherwise hide. This one liner seems to do what you need it to:

document.getElementById("theForm").style.display = document.referrer ?  "block" : "none";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM