views:

154

answers:

3

is there a way to replace a whole web page using GreaseMonkey?

basically a redirection but the address bar still shows the original address.

i want the original address to show, but i want to load a modified web page from my hard drive without anyone knowing.

thanks

A: 

The easiest way I could see doing this would be to remove the contents of the body, insert an iframe (100%x100%), and set its source to the path of your choosing.

Jonathan Sampson
A: 

Yes, you could probably do this. How hard it will be depends a lot on how complicated the source and destination pages are. If they're both simple html, it will be easy. If one or the other or both have a lot of fancy styling and scripting, it could be a bit tricky, but it'd be possible.

One easy way might be to create an iframe that fills the whole page?

Or, loop over all of the children of the "body" tag of the html and delete them; then insert the iframe, or insert the contents of the other page as innerHTML.

dmazzoni
+1  A: 

mh... this should change page contents

unsafeWindow.document.documentElement.innerHTML='DEFACED!!!!!!1!!!'

To get those contents you could rely upon GM_xmlhttpRequest()

The real problem here is at what time greasemonkey is triggered; that is: too late for the user not to notice what happened.

I'm not sure about what you're trying to achieve here. Is it a prank, or a lab user access scheme?

Anyway for the user not to notice you'll eventually need to do one of those two:

  1. write a full fledged firefox extension that kicks in earlier than GM in the loading process,
  2. add a non-transparent proxy in the way.
ZJR
Under Chrome and Chromium (OSS counterpart) adding `@run-at document-start` to the UserScript headers should help with the timing. I tested it under firefox and found no improvements, though.
ZJR
No need for `unsafeWindow`. `document.documentElement.innerHTML='DEFACED!!!!!!1!!!'` should work.
NV