Home > Programming, Servers & Scripts >

Back Button Script That Works With AWS? (12)


06-25-2019 06:11 AM #1 jabong82 (Member)
Back Button Script That Works With AWS?

I had to switch from a Beyond Hosting CDN to AWS, but I noticed when I migrated everything over for some reason my back button scripts don't work any more.

Would anyone have a guess at why that might be?

Also does anyone have a back button script that they could share that works with AWS?

Thanks in advance


06-25-2019 08:35 AM #2 sprice (AMC Alumnus)

https://stmforum.com/forum/showthrea...topped-working


06-25-2019 10:00 AM #3 jabong82 (Member)

The script Im using still works, it just doesn't work since I moved to AWS.

It is as below:


<script type="text/javascript">
window.history.pushState('other.php', 'Other Page', 'other.php');
window.history.pushState('initial.html', 'Initial Page', 'initial.html');
</script>

<script type="text/javascript">
window.addEventListener("popstate", function(e) {
if(document.URL.indexOf("other.php") >= 0){
document.location.href = document.location;
}
});
</script>


I have to change something in here I think, I just don't know what.

The above script used to work when the URL was: www.mydomain.com

However after switching to AWS my landing pages are delivered as: http://www.mydomain.com.s3-website-u...age/index.html


06-25-2019 04:46 PM #4 erikgyepes (Moderator)

I'm on phone so just read the code without testing it.

To my understanding it may have to do something with your URL as the second part of the script checks for other.php in the URL.

Do you have your own CNAMe domain with same path as you used to have at your previous hosting or is the URL some random hash from CDN?

Instead of including the whole URL in that check instead of other.php I would add nameofyourlander.html ie. index.html or in case its random hash then that randomhash.html

Not 100% sure here, but I think that part causes you the issue.



Sent from my SM-G975F using STM Forums mobile app


06-25-2019 07:00 PM #5 jabong82 (Member)

Quote Originally Posted by erikgyepes View Post
I'm on phone so just read the code without testing it.

To my understanding it may have to do something with your URL as the second part of the script checks for other.php in the URL.

Do you have your own CNAMe domain with same path as you used to have at your previous hosting or is the URL some random hash from CDN?

Instead of including the whole URL in that check instead of other.php I would add nameofyourlander.html ie. index.html or in case its random hash then that randomhash.html

Not 100% sure here, but I think that part causes you the issue.



Sent from my SM-G975F using STM Forums mobile app
Yes there is a "other.php" file that the code checks for that is also uploaded, but I think the location of the file has changed as well since now everything starts with the amazon url.

So I'm not sure where I have to make an edit for it to work lol


06-25-2019 08:39 PM #6 twinaxe (Senior Moderator)

When there is a PHP file and you uploaded the lander to a CDN then maybe this could be the problem.

CDNs usually only work with static files like HTML, CSS, JS, images.

So when there is a PHP file needed for the script then maybe the CDN doesn´t catch the file and thus the script is not working.


06-25-2019 10:31 PM #7 jabong82 (Member)

Quote Originally Posted by twinaxe View Post
When there is a PHP file and you uploaded the lander to a CDN then maybe this could be the problem.

CDNs usually only work with static files like HTML, CSS, JS, images.

So when there is a PHP file needed for the script then maybe the CDN doesn´t catch the file and thus the script is not working.
You know I think you may be right.

Does anyone have a back button script that works with CDNs they could share?


06-26-2019 01:07 AM #8 sprice (AMC Alumnus)

Have you tried this one?

I can't seem to get it to work when testing it on my own devices. But when adding it to my campaign I can see that it does in fact get clicks. It was recommended in the other thread I shared.

<script type="text/javascript">
! function () {
var t;
try {
for (t = 0; 10 > t; ++t) history.pushState({}, "", "#");
onpopstate = function (t) {
t.state && location.replace("yourbackbuttonurl.com")
}
} catch (o) {}
}();
</script>


06-27-2019 07:03 AM #9 jabong82 (Member)

Quote Originally Posted by sprice View Post
Have you tried this one?

I can't seem to get it to work when testing it on my own devices. But when adding it to my campaign I can see that it does in fact get clicks. It was recommended in the other thread I shared.

<script type="text/javascript">
! function () {
var t;
try {
for (t = 0; 10 > t; ++t) history.pushState({}, "", "#");
onpopstate = function (t) {
t.state && location.replace("yourbackbuttonurl.com")
}
} catch (o) {}
}();
</script>
Actually this script actually works thank you for this!

Is your page in PHP? I think if your landing pages are in HTML I think the script should work for you.


06-27-2019 07:15 AM #10 eurosen (AMC Alumnus)

PHP does not work on AWS if I remember correctly.


06-27-2019 09:36 AM #11 diplomat (Member)

Quote Originally Posted by eurosen View Post
PHP does not work on AWS if I remember correctly.
If you are using CloudFront + S3 then yes, you can't run PHP there. Just HTML/CSS and Javascript.


06-27-2019 11:38 AM #12 hvostopuz (Member)

In chrome update 72 all scripts backbutton are disabled (&nbsp;


Home > Programming, Servers & Scripts >