List Info

Thread: window.location.replace 404




window.location.replace 404
user name
2006-05-31 12:33:05
I have code like the following which skips to another page
if a certain link
is present on the first page. The link in the document is a
relative link
(no protocol or hostname) like <a
href="/skiptopath/skiptopage?action=showAll">
Link Text </a>

// Skip to page if link found
function maybeSkipTo() {  
  var re =
/<a[^>]*?href=\"([^\"]*)\"[^>]
*>(?:\s|&nbsp;)*Link(?:\s|&nbsp;)*Text(?:\s|&a
mp;n
bsp;)*<\/a>/i;
  skipToURL =
document.getElementsByTagName('body')[0].innerHTML.match(r
e);
  if (skipToURL) {
    GM_log("maybeSkipTo
window.location.replace('"+window.location.protocol+
'|'+window.location.host
name+'|'+skipToURL[1]+"')");
 
window.location.replace(window.location.protocol+window.loca
tion.hostname+sk
ipToURL[1]);
    return false;
  } else {
    return true;
  }
}

I originally had this code included directly in one script
and it seemed to
work fine. Then I moved it to a script that is eval'ed by
the script
included by GM. When eval'ed it gets a 404 error and the
URL in the Firefox
location box is https:
//{first_page_URL_path_w/o_file}{skip_to_URL_full_pathname_a
nd_parameters}
like so: 
https:
//www.host.com/firstpagepath/firstpage/www.host.com/skiptopa
th/?action=showA
ll

If I comment out the
window.location.protocol+window.location.hostname+ it
seems to work when eval'ed but does not load the new page
when included
directly. In summary:

Included, full URL --> seems to work
Included, relative URL --> no page load
Eval'ed, full URL --> bad URL, 404
Eval'ed, relative URL -- seems to work

Does anyone have an explanation or ideas as to what is
happening?

--
Regards, Phil Friedman - Auto Europe
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )