By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,375 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,375 IT Pros & Developers. It's quick & easy.

Preventing Page Reload

P: n/a
Hi All

Programming newbie here, so please be gentle :)

I've noticed some websites have a URL checking script that check to see
the URL in the address bar of the browswer, and can reload/redirect the
page based on this. For example, take the chunk of code below (excuse
the ugly formatting - its a decent size chunk, and I tried to compact
it somewhat)

<script language="JavaScript">
checkURL();
function checkURLl() {
try
{ if (
top.location.hostname!="www.yahoo.com") {
exit=false;
if ( (top.location.hostname).indexOf("yahoo") != -1 )
{ parent.location="http://www.yahoo.com"; }
} }
catch(e)
{
exit=false;
var loc = document.URL;
if ( loc.indexOf("yahoo") != -1 )
{ parent.location="http://www.yahoo.com"; }
} }
function placeFocus() {
checkURL();
if (document.forms.length 0) {
var field = document.forms[0];
for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") || (field.elements[i].type ==
"textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[0].elements[i].focus();
break;
} } } }
</script>

This code is (supposed) to make sure that the proper URL is in the
address bar (here it would be yahoo.com), and if not, it would reload
the browser using the proper URL. An example of this would be someone
who is hiding the URL they are sending you to using frames. So even
though you are looking at the yahoo.com website, the URL in your
address bar shows something besides yahoo.com. Is there a way to defeat
this script short of disabling Javascript in the browser?

TIA
Samantha

Oct 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
yes, just hit stop before it gets executed. for instance when you use
google translate to translate mail.yahoo.com from english to english to
defeat bossy IT staff who have tried to ban google it will try to
refresh, just hit stop, and login as normal to the yahoo beta. job done

If you are talking about writing script that stops it, then try
greasemonkey extension in firefox, and inject

window.onunload = function()
{
confirm('you really want to navigate away?');
}

that kind of thing.

If the redirect is on a loop or interval though you will be answering
that question alot, however if you just stop it from unloading
completely, yuo will not be able to navigate away when you want to.

what about injecting a checkbox top right, which starts off checked,
then your onunload statement would be

//pseudocode
if(checkbox is checked)
{
window.onunload = function()
{
return false;
}
}
else
{
confirm('leave page?');
}
Or another method, how about using a proxy server like fiddlertool on
windows which you then write a rule for which parses out certain
javascript phrases so that no redirect code is ever present in the
webpages. This would slow up your browsing as all pages would go via
fiddler, so then install the foxyproxy extension and set it up to only
redirect certain known annoying javascripts, and urls to the proxy,
leaving others to pass through.

Ah white-hat hacking, i love it. But just be ethical, use it for good.

;)

Oct 27 '06 #2

P: n/a
sa*********@yahoo.com said the following on 10/27/2006 3:51 PM:

<snip>
Is there a way to defeat this script short of disabling
Javascript in the browser?
Yes, stop trying to frame someone else's content and you don't have to
worry about it anymore.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.