How can I tell where someone has come from, so I can send them back
Forum rules
IMPORTANT NOTE!!
DO YOU HAVE A QUESTION OR PROBLEM AND WANT QUICK HELP?
THEN PLEASE SHARE A "DEMO" PROJECT.
PLEASE READ THE FORUM RULES BEFORE YOU POST:
http://www.wysiwygwebbuilder.com/forum/viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/getting_started.html
WYSIWYG Web Builder FAQ
IMPORTANT NOTE!!
DO YOU HAVE A QUESTION OR PROBLEM AND WANT QUICK HELP?
THEN PLEASE SHARE A "DEMO" PROJECT.
PLEASE READ THE FORUM RULES BEFORE YOU POST:
http://www.wysiwygwebbuilder.com/forum/viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/getting_started.html
WYSIWYG Web Builder FAQ
How can I tell where someone has come from, so I can send them back
I want to open a web site I have built from another place. But not just one place, 3 or 4 of them. And, then the user has finished on my site, I want them to click on a button and have it send them back.
I have no idea how I am going to do that. Is there some way I can tell where someone has come from and pop that site in a variable in a button?
To give you some idea, if you click here https://dev2.dprevived.com/ and look at the top, you will see a menu item called "GDPR". Click on that and it takes you to my site where you can click on various documents and fill out forms. Once finished, in theory, you click on the button that says 'Back to forums'. But that has a fixed link which, at the moment, takes you back to a different site (dev1 - because I am messing around). I'd like the button to take me back to dev2. However, if I came to my site from dev1, I want it to go back there.
Any thoughts appreciated.
Cheers
Alan
I have no idea how I am going to do that. Is there some way I can tell where someone has come from and pop that site in a variable in a button?
To give you some idea, if you click here https://dev2.dprevived.com/ and look at the top, you will see a menu item called "GDPR". Click on that and it takes you to my site where you can click on various documents and fill out forms. Once finished, in theory, you click on the button that says 'Back to forums'. But that has a fixed link which, at the moment, takes you back to a different site (dev1 - because I am messing around). I'd like the button to take me back to dev2. However, if I came to my site from dev1, I want it to go back there.
Any thoughts appreciated.
Cheers
Alan
- BaconFries
-
- Posts: 5914
- Joined: Thu Aug 16, 2007 7:32 pm
Re: How can I tell where someone has come from, so I can send them back
Maybe not what you need but the Go Menu might be of use. See the following
https://www.wysiwygwebbuilder.com/navigation.html
https://www.wysiwygwebbuilder.com/navigation.html
Re: How can I tell where someone has come from, so I can send them back
You could try this, add a onclick event to the button:
For example, if using a themeable button for the return button, do not set a link. Click on the events tab, select onclick, action = javascript and enter: history.back()
This only will work if the previous page exists in your history list which it should since they just clicked the button.
Code: Select all
onclick="history.back()"
This only will work if the previous page exists in your history list which it should since they just clicked the button.
Re: How can I tell where someone has come from, so I can send them back
Crispy, thanks for that. I will try it and get back to you.
Alan
Alan
Re: How can I tell where someone has come from, so I can send them back
It almost works.
If I go into my web site from the forum and immediately click the 'back to forums' button, it works.
However, if I click on one of the form buttons (which displays a form below the buttons) and click 'back to forums', it does nothing. If I click it again, it works. So it's just going back through the history till it gets to the place we came from.
Thanks for the idea though.
Alan
If I go into my web site from the forum and immediately click the 'back to forums' button, it works.
However, if I click on one of the form buttons (which displays a form below the buttons) and click 'back to forums', it does nothing. If I click it again, it works. So it's just going back through the history till it gets to the place we came from.
Thanks for the idea though.
Alan
- BaconFries
-
- Posts: 5914
- Joined: Thu Aug 16, 2007 7:32 pm
Re: How can I tell where someone has come from, so I can send them back
As crispy68 reply you could also try the following inserting as he mentioned.
Will only work if the previous pages exist in your history list
Code: Select all
onclick="history.go(-2)
Re: How can I tell where someone has come from, so I can send them back
But that assumes I am going back 2 clicks, doesn't it?. There are an unknown number. It depends how many times the user has done something on my site before going back.
What I would love is if the site it came from could be passed as a parameter which I could save and then use. But failing that, I'll just get my site opened in a new tab so the old one is still there.
Alan
What I would love is if the site it came from could be passed as a parameter which I could save and then use. But failing that, I'll just get my site opened in a new tab so the old one is still there.
Alan
Re: How can I tell where someone has come from, so I can send them back
Did you try chatgpt?
Q: Write a script that stores the URL from which the user came so that it can be later used for a button to navigate back to that website.
A: You can create a simple script using JavaScript to store the URL where the user came from and then use it to create a button that allows them to go back to that website. Here's an example:
In this script, we first define a function storeReferringURL that stores the referring URL in the session storage when the page loads. Then, we create a button that, when clicked, calls the goBackToReferringURL function, which retrieves the stored referring URL from session storage and redirects the user back to that URL.
Please note that this script relies on the document.referrer property to get the referring URL, which may not always be available or accurate depending on the user's browsing behavior and browser settings. Additionally, session storage is used to store the URL temporarily during the user's session. If you need to persist the referring URL across sessions, you may consider using server-side storage or cookies instead.
Q: Write a script that stores the URL from which the user came so that it can be later used for a button to navigate back to that website.
A: You can create a simple script using JavaScript to store the URL where the user came from and then use it to create a button that allows them to go back to that website. Here's an example:
Code: Select all
<!DOCTYPE html>
<html>
<head>
<title>Store and Go Back</title>
</head>
<body>
<script>
// Function to store the referring URL in a session variable
function storeReferringURL() {
// Check if the browser supports the session storage
if (typeof(Storage) !== "undefined") {
// Store the referring URL in a session variable
sessionStorage.setItem("referringURL", document.referrer);
} else {
console.log("Session storage is not supported in this browser.");
}
}
// Function to go back to the referring URL
function goBackToReferringURL() {
// Check if the session variable exists
if (sessionStorage.getItem("referringURL")) {
// Redirect the user to the referring URL
window.location.href = sessionStorage.getItem("referringURL");
} else {
console.log("No referring URL found.");
}
}
// Call the function to store the referring URL when the page loads
storeReferringURL();
</script>
<p>This is the current page.</p>
<!-- Button to go back to the referring URL -->
<button onclick="goBackToReferringURL()">Go Back to Referring URL</button>
</body>
</html>
Please note that this script relies on the document.referrer property to get the referring URL, which may not always be available or accurate depending on the user's browsing behavior and browser settings. Additionally, session storage is used to store the URL temporarily during the user's session. If you need to persist the referring URL across sessions, you may consider using server-side storage or cookies instead.
-
-
- Posts: 29
- Joined: Wed Feb 23, 2022 7:03 pm
Re: How can I tell where someone has come from, so I can send them back
Hi Alan,
You could grab the contents of the Referer Header and store it, it looked like this when I clicked on your GDPR link:
Referer https://dev2.dprevived.com/
You may read that the Referer is unreliable but I doubt you are going to spoof your own headers.
Of course if someone goes directly to the page because they saved the URL, the Referer will not be there so you will have to provide a default return page in your logic.
Another option is to use session-storage on the client's browser.
On the dev1 and dev2 pages store the page name you want them to return to using something like this, set it based on the landing page in this case dev2:
sessionStorage.setItem('retPageLink','https://dev2.dprevived.com');
and then on your other pages use: sessionStorage.getItem('retpageLink'); to retrieve the appropriate link and dynamically apply it to your button.
You would still need to provide a default value in your logic to allow for them going directly to the page if they didn't start out on dev1 or dev2.
Just a thought.
Regards
Parker
You could grab the contents of the Referer Header and store it, it looked like this when I clicked on your GDPR link:
Referer https://dev2.dprevived.com/
You may read that the Referer is unreliable but I doubt you are going to spoof your own headers.
Of course if someone goes directly to the page because they saved the URL, the Referer will not be there so you will have to provide a default return page in your logic.
Another option is to use session-storage on the client's browser.
On the dev1 and dev2 pages store the page name you want them to return to using something like this, set it based on the landing page in this case dev2:
sessionStorage.setItem('retPageLink','https://dev2.dprevived.com');
and then on your other pages use: sessionStorage.getItem('retpageLink'); to retrieve the appropriate link and dynamically apply it to your button.
You would still need to provide a default value in your logic to allow for them going directly to the page if they didn't start out on dev1 or dev2.
Just a thought.
Regards
Parker
- wwonderfull
-
- Posts: 1579
- Joined: Fri Aug 21, 2020 8:27 am
- Contact:
Re: How can I tell where someone has come from, so I can send them back
Late on the code wars
Try this one:
Note: goBackButton is the button's ID

Try this one:
Note: goBackButton is the button's ID
Code: Select all
<script>
document.getElementById('goBackButton').addEventListener('click', function() {
var params = new URLSearchParams(window.location.search);
var referrer = params.get('referrer');
if (referrer) {
var savedReferrer = referrer;
console.log('Saved Referrer:', savedReferrer);
}
window.history.back();
});
</script>
Re: How can I tell where someone has come from, so I can send them back
Thank you all. I've gor more things to play with
Alan
Alan