View Full Version : JS "Breaks" Browser Back Button
peterinwa
03-29-2003, 03:49 PM
I use JS in Frames to create a calculator. For each calculation you make, you'd have to hit the browser Back button an additional time to "Back" out of my webpage. Make 20 calculations and you'd have to hit Back 20 times for it to work. So I get a lot of nasty e-mails from people that think I'm trying to "trap" them into staying at my website.
Is there a way to avoid or work-around this?
Thanks, Peter
P.S. I don't think using Frames has anything to do with it but thought I'd mention it to be sure. I think it's calling the JS functions.
scroots
03-29-2003, 04:33 PM
have you go your source code so people can take a look
scroots
peterinwa
03-29-2003, 04:37 PM
My source code is massive. I guess the question is, "Is this normal and common?"
If not, I can create a small test page to demonstrate it and post the code.
Graeme Hackston
03-29-2003, 04:45 PM
I think you should post a sample. There might be a way to do it without affecting the history.
cheesebagpipe
03-29-2003, 11:21 PM
Are you calling document.write() or using a form submission for the calculations? Clearly you're loading new pages into the history, necessitating backing up through it to navigate. Shouldn't be necessary...can't recommend a solution without seeing something more.
peterinwa
03-30-2003, 12:14 AM
I'll still post a simple example of the code when I have time. But to answer the last question, I do a document.write... but just once to create the page.
I just tried it and see that each time I click on the Calculate button it adds FOUR items to the history. I believe this is because clicking on the button calls four functions. Well, actually it calls more so I can't account for it.
www.caloriesperhour.com/index_burn.html
Peter
patrick
03-31-2003, 10:35 PM
Its not a pretty solution, but you could make a link that works as a back button. Maybe you can count the number of times the normal back button should be pressed, and go back that number of times when a visitor presses the back link. I copied an explanation of how to make a back button:
Essentially this tip involves accessing the browsers History object. In JavaScript, using the following function :
<SCRIPT LANGUAGE="JavaScript">
<!--
function retrace()
{
history.back()
}
// -->
</SCRIPT>
accesses the browsers history object when called from a link such as :
<A HREF="#back" OnClick="retrace()">Go back</A>
or a button such as :
<FORM>
<INPUT TYPE="BUTTON" NAME="GOBACK" VALUE="Go back 1" OnCLick="retrace()">
</FORM>
which forces re-loading of the document last viewed in the browser.
NOTE : At the time of writing, this method worked in Netscape (even within framed documents), but caused Internet Explorer to crash (as did a VisualBasic Script variation of the script).
The history object also takes 'forward' and 'go(int)' methods, allowing forward navigation and navigation across any integer (positive or negative) number of pages in the history list.
patrick
03-31-2003, 11:02 PM
I visited your site and noticed that even when you run your mouse over a button, a new page is opened to play a sound.
// Function to make sound frame
function makeSound(sound,n){
if (brType!="MIE"){}
else {
s="<html><head></head><body>";
if (sound!="none"){s+="<bgsound src='sounds/"+sound+"' loop="+n+">"}
s+="</body></html>";
parent.sound.document.write(s);
parent.sound.document.close()}}
When you press the back button, you hear the sound again! Maybe you can use other ways that won't change your history. I happen to have a testfile for noisy links from www.javascripts.com :
<html>
<head>
<title></title>
<script><!--
function playTunes() {
document.all.base.src = "chunk.mp3"
}
function playTunes1() {
document.all.base.src = "cash.mp3"
}
function playTunes2() {
document.all.base.src = "dent.mp3"
}//-->
</script>
</head>
<body><CENTER>This is a very simple script.</CENTER>
<CENTER>Add as many sounds as you like, easy to configure</CENTER><CENTER>Add as many differant, sounds to as many differant links</CENTER><CENTER>onclick....and other commands can also be used with this script</CENTER><br>
<bgsound id="base"><form>
<center><img src="http://www.users.bigpond.com/dsjcullen/addesign.gif" onmouseover="playTunes()" onmouseout="playTunes()"></center><br><br>
<center><img src="http://www.users.bigpond.com/dsjcullen/addesign.gif" onmouseover="playTunes()" onmouseout="playTunes1()"></center><br><br>
<center><img src="http://www.users.bigpond.com/dsjcullen/addesign.gif" onmouseover="playTunes()" onmouseout="playTunes2()"></center><BR>
<CENTER><a href="http://www.users.bigpond.com/dsjcullen/MP3s.zip">Click Here</a></CENTER>
<CENTER>To down load the Zip File, with approx 95 differant MP3 sounds for you to use on your site....(approx 508kb)</CENTER>
</form>
</body>
</html>
peterinwa
03-31-2003, 11:18 PM
Let me see if I can explain why I do it that way.
Some of the sounds caused by onMouseOver I want to run continuously until onMouseOut. So onMouseOver writes a frame with the sound running continuously.
Then to stop it on onMouseOut I re-write it with no sound.
Only way I could figure out to stop the sound! It works well except for the Back problem.
Thanks, Peter
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.