469,271 Members | 1,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Preventing Page Reload

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">
function checkURLl() {
{ if (
top.location.hostname!="www.yahoo.com") {
if ( (top.location.hostname).indexOf("yahoo") != -1 )
{ parent.location="http://www.yahoo.com"; }
} }
var loc = document.URL;
if ( loc.indexOf("yahoo") != -1 )
{ parent.location="http://www.yahoo.com"; }
} }
function placeFocus() {
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")) {
} } } }

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?


Oct 27 '06 #1
2 2142
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

if(checkbox is checked)
window.onunload = function()
return false;
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
sa*********@yahoo.com said the following on 10/27/2006 3:51 PM:

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.

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.

By using this site, you agree to our Privacy Policy and Terms of Use.