View Full Version : Stop a page from loading via JS
Purelimit
08-22-2003, 03:45 PM
I have been trying this code for a while but whenever I use the code an error alert pops up. Does anyone have an alternate code or can fix this one
function stop()
{
window.stop();
}
basically I wanna have a link <a href="javascript:stop()">Off</a> that stops the page from loading. If anyone could give me a nice script I would be eternally greatful.
fredmv
08-22-2003, 03:48 PM
See, the thing is, using the stop method should work -- It's getting confused because that's what you're using as a function name (it's a pre-defined JavaScript method name).
Since a function isn't even needed, try this:
<a href="#" onclick="window.stop();">Stop.</a>
Hope that helps you out.
Purelimit
08-22-2003, 04:24 PM
Sorry the code you gave me caused an error. All I wanted was to remove the alert and stop the page. As you can tell JS is not my forte.
fredmv
08-22-2003, 04:31 PM
It works fine for me, weird.
Purelimit
08-23-2003, 03:26 AM
Maybe I am not understanding you correctly. Can you link me to a page that has that method working?
ahosang
08-24-2003, 12:20 AM
For completeness, always return false:
<a href="#" onclick="stop();return false">Stop loading</a>
No need to define your own stop function as fredmv said
Purelimit
08-24-2003, 02:01 AM
Nope it fails. I get an error like before.
<script language="JavaScript">
function refresh()
{
window.location.reload( false );
}
function stop()
{
window.stop();
}
</script>
^ Thats a script you asked me to remove the stop function so I did and it turns out like this
<script language="JavaScript">
function refresh()
{
window.location.reload( false );
}
</script>
Now for the URL
<a href="javascript:refresh()">On</a> | <a href="javascript:stop()">Off</a>
You asked me to change it to
<a href="javascript:refresh()">On</a> | <a href="#" onclick="stop();return false">Off</a>
and I did. When I click off I get an error message. Doesn't work :(
glenngv
08-25-2003, 03:19 AM
FYI, window.stop() is a NS-only method
Purelimit
08-25-2003, 03:45 AM
Oh I see. That explains it. So does anyone have a universal method of stopping the page load.
brothercake
08-25-2003, 03:59 AM
Until this thread, I didn't even know there was a proprietary method.
Window loading is not something a webpage should be able to control, anymore than it should have access to the history, the window properties or anything else that's part of the computer, rather than part of the document.
Maybe step back from your original question - why do you want stop page loading at all - what's the bottom-line purpose?
Purelimit
08-25-2003, 07:57 AM
Well I have a musical theme going through the page and if you click the stop button on the browser it stops the music. I figured if people want to stop the music playing they could click a stop link but I guess I am wrong. I know there are alternative methods to controlling a musical theme with hyperlinks so anyone have any ideas. Also thanks for the help you have given me so far :)
fredmv
08-25-2003, 09:09 AM
If you're using an <embed> element for the music, and it's the first one in the document, try this:
<a href="#" onclick="document.embeds[0].stop();">Stop Music.</a>
If it isn't the first one, give it an ID and stop it like this (you could just find where it is in the embeds array but this may be easier for you):
<a href="#" onclick="document.getElementById('theid').stop();">Stop Music.</a>
If it isn't an <embed> let us know what tag you're using.
Hope that clears thing up. :thumbsup:
glenngv
08-25-2003, 09:36 AM
<embed> tag is NS-only too. Here's a cross-browser way to play/stop audio in a page:
http://www.javascripter.net/faq/sound/play.htm
fredmv
08-25-2003, 03:24 PM
I've used <embed> under IE and it seems to work fine...
Purelimit
08-26-2003, 05:20 AM
I would like to thank all of you for helping me. I finally got this thing to work so :)
jeroMe22
01-21-2005, 09:56 PM
I would like to thank all of you for helping me. I finally got this thing to work so :)
Hello :)
could you please help me how u did it, because i haev the same pb!
the webpage is http://clanwarp.strategie-expert.com/warp.html
I tried this but it doesnt work
<bgsound src="AoE-theme.mid" loop="1"></bgsound>
<a href="#" onclick="window.stop();" language="javascript"><img src="images/sound-off.gif" border="0"></a>
:confused: :confused: :confused:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.