Jump to content

Back 2 pages when page loads


son

Recommended Posts

  • 1 month later...
I guess I just don't understand why he's trying to develop on a server that he doesn't have control over, that doesn't make sense to me. That seems like a pretty counter-productive way of doing business.
Sorry for super late reply.I cannot change settings etc on server where shopping basket is sitting as this is a pre-made software. You have only ways to customise the interaction with the actual live site (on different server) without having to many options. As for the continue shopping button coming with the shopping cart you can only specify a url (could include one parameter, but this is it) without the abitility to add any server side programming. Javascript could be done as you have the ability to add html (Javascript) to webpage's header. Hope this makes it a bit clearer.Son
Link to comment
Share on other sites

I think the only remaining solution is to give a static URL to the remote page and, at that static URL, redirect the user based on $_SESSION['back'].
Do you have any questions regarding that?
Link to comment
Share on other sites

Do you have any questions regarding that?
Yes, could I customise a 'go back one page in browser history' script, so it will disregard the shopping cart page itself? Meaning if the user refreshes shopping cart three times and user clicks onto 'go back' he/she will actually go to page before shopping cart and not to shopping cart with quantities as before the last refresh. Hope it is clear what I mean...Son
Link to comment
Share on other sites

If the user is refreshing the cart by clicking links, each linked page will be in the browser's history; if they're clicking the Refresh button, the Back button will send them one link back. I know of no reliable way to alter this behavior.BTW, I didn't mean to sound curt in my last post; I was in a rush and needed to call attention to that quote.

Link to comment
Share on other sites

If the user is refreshing the cart by clicking links, each linked page will be in the browser's history; if they're clicking the Refresh button, the Back button will send them one link back. I know of no reliable way to alter this behavior.BTW, I didn't mean to sound curt in my last post; I was in a rush and needed to call attention to that quote.
Do not worry, did not come acrsoss curt at all. A shame that it is not possible. Just one last questions from someone who does not have a clue about the working of java script: Could it work to have a script that has the behaviour to go back one page in browser history, but if that is the shopping cart (checked with window.location.href) there is a loop that says if when you go back one page and it is the shopping cart url then go back two page (or another page). If that still is the same, then go back three pages and and and. Does this sound ok to you? If yes, might try to get something working...Son
Link to comment
Share on other sites

The actual URLs in the history are concealed for privacy reasons. I tried to implement a cross-page document.cookie loop to go back until either the correct page was found or a certain number of links had been gone back over, but one cookie always refused to be deleted and that broke all forward links (because each page already visited always sent me back to the "correct" page after the loop had been executed). I think it should work, and I'm going to ask about it.

Link to comment
Share on other sites

The actual URLs in the history are concealed for privacy reasons. I tried to implement a cross-page document.cookie loop to go back until either the correct page was found or a certain number of links had been gone back over, but one cookie always refused to be deleted and that broke all forward links (because each page already visited always sent me back to the "correct" page after the loop had been executed). I think it should work, and I'm going to ask about it.
That would be greatly appreciated, cheers!Son
Link to comment
Share on other sites

The code I posted in the other thread is still broken, but I found a workaround. If you know the folder which the HTML pages are contained in, you can attach all cookies to that folder. It's not as easy as it would ideally be, but it works. In the code below, replace /to/HTML/ with your path. Do not include any domain; the beginning slash specifies the root directory and no domain is present in the path which is causing the problems.Cookie.js

function Cookie(name, value, days){	this.name = name;	if(typeof value !== 'undefined')		this.set(value, days);}Cookie.prototype = {	set: function (value, days){		if(days){			var date = new Date();			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));			var expires = "; expires=" + date.toGMTString();		}else			var expires = "";		document.cookie = this.name + '=' + value + expires + '; path=/to/HTML/';	},	get: function (){		var nameEQ = this.name + "=";		var ca = document.cookie.split(';');		for(var i = 0; i < ca.length; i++) {			var c = ca[i];			while (c.charAt(0) === ' ')				c = c.substring(1, c.length);			if (c.indexOf(nameEQ) == 0)				return c.substring(nameEQ.length, c.length);		}		return null;	},	erase: function (){		this.set('', -1);	}};

main page

<html>	<head>		<title>Titled Document</title>		<script type="text/javascript" src="Cookie.js"></script>		<script type="text/javascript">			(function (){ // will execute immediately				var cookie = new Cookie('back');				if(cookie.get() !== null)					cookie.erase();			})();		</script>	</head>	<body>		<a href="test1.html">Test 1</a> <a href="test2.html">Test 2</a>	</body></html>

test1.html and test2.html

<html>	<head>		<title>Titled Document</title>		<script type="text/javascript" src="Cookie.js"></script>		<script type="text/javascript">			(function (){ // will execute immediately				var limit = 10;				var cookie = new Cookie('back');				var back = parseInt(cookie.get());				if(!isNaN(back))					if(back < limit){						cookie.set(back + 1);						history.back();					}else						cookie.erase();			})();		</script>	</head>	<body>		<a href="test1.html">Test 1</a> <a href="test2.html">Test 2</a> <a id="back">To go back, click your browser's "Back" button.</a>				<script type="text/javascript">			Element.prototype.on = function (action, response, capturing){				var listener = 'on' + action;				this[listener] = response;				var w3c = 'addEventListener';				var ie = 'attachEvent';				if(typeof this[w3c] === 'function')					this[w3c](action, response, !!capturing);				else if(typeof this[ie] === 'function')					this[ie](listener, response);			};			(function (){ // will execute immediately				var back = document.getElementById('back');				back.on('click', function(event){						document.cookie = 'back=0;';						history.back();						return false;					});				back.innerHTML = 'Go back.';				back.href = '#back';			})();		</script>	</body></html>

Link to comment
Share on other sites

My bad... I just found my stupid mistake. Use the lone slash as your path and replace the last code box (for test1.html and test2.html) with this one:

<html>	<head>		<title>Titled Document</title>		<script type="text/javascript" src="Cookie.js"></script>		<script type="text/javascript">			var cookie = new Cookie('back');			(function (){ // will execute immediately				var limit = 10;				var back = parseInt(cookie.get());				if(!isNaN(back))					if(back < limit){						cookie.set(back + 1);						history.back();					}else						cookie.erase();			})();		</script>	</head>	<body>		<a href="test1.html">Test 1</a> <a href="test2.html">Test 2</a> <a id="back">To go back, click your browser's "Back" button.</a>				<script type="text/javascript">			Element.prototype.on = function (action, response, capturing){				var listener = 'on' + action;				this[listener] = response;				var w3c = 'addEventListener';				var ie = 'attachEvent';				if(typeof this[w3c] === 'function')					this[w3c](action, response, !!capturing);				else if(typeof this[ie] === 'function')					this[ie](listener, response);			};			(function (){ // will execute immediately				var back = document.getElementById('back');				back.on('click', function(event){						cookie.set(0);						history.back();						return false;					});				back.innerHTML = 'Go back.';				back.href = '#back';			})();		</script>	</body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...