4

I want to force external 3rd party scripts (on seperate domains) to use my own custom implementation of document.write when I load them on my domain.

ie:

document.write = function(args) {
    // My custom Function
    }

This works fine for scripts on the same domain, but scripts on other domains use the browser default. Can I override this?

FlySwat
  • 172,459
  • 74
  • 246
  • 311
  • where have you put document.write = function... in your html? – shahkalpesh May 29 '09 at 18:28
  • Its in an external script that is loaded (fully) before any of the other scripts. This script actually dynamically loads the other scripts, so it is guaranteed to run first. – FlySwat May 29 '09 at 18:40
  • I guess your code, if executed last should run your implementation, when calling document.write(...). – shahkalpesh May 29 '09 at 19:22
  • Are the other scripts writing to an iframe? Because that's the only way a different document.write could be getting called, because it's on a different document. – noah Jun 15 '10 at 02:53

1 Answers1

0

Here you are:

(window.HTMLDocument ? HTMLDocument.prototype : document).write = function(s) {
    this.title = s;
}

Both in IE and in non-IE, "this" object is the browser document object.

Sergey Ilinsky
  • 31,255
  • 9
  • 54
  • 56
  • That doesn't make a bit of difference :( – FlySwat May 29 '09 at 22:54
  • Thank you guys for minusing my help, however I am not going to withdraw my right answer. Anyway, I tested what I proposed and it indeed works. You can see it working: http://www.amplesdk.com/share/test.html – Sergey Ilinsky May 30 '09 at 05:56