-2

How can I replace a function by javascript?

I want to disable the function function Qa(a){try{var b=(document.forms[0].q||"").value;b&&(a.href=a.href.replace(/([?&])q=[^&]*|$/,function(a,c){return(c||"&")+"q="+encodeURIComponent(b)}))}catch(c){q(c,"sb","pq")}} in Google Maps. It shows additional page on any external link.

Google Maps generates all the code of the page on the fly. So when the page is loaded it doesn't contain 'Qa' function yet.

The following answer doesn't help: Insert code into the page context using a content script

Community
  • 1
  • 1
Dmitry
  • 14,306
  • 23
  • 105
  • 189

1 Answers1

0

Every global (user-created) function is property of window. So you could reassing it after it has been loaded.

window['Qa'] = function(a) { };
Peter Uhnak
  • 9,617
  • 5
  • 38
  • 51
  • Thanks. But webpage hungs on that code. Google Maps generates all the code of the page on the fly. So when the page is loaded it doesn't contain 'Qa' function yet. – Dmitry Apr 11 '15 at 11:03
  • It hungs even when I run the code after several seconds after the page is displayed. If I write "window['Qa2'] = ..." there is no hung. – Dmitry Apr 11 '15 at 11:22