Chrome extension script injection

becraig used Ask the Experts™
I need to figure out how to inject a script into a webpage via a Chrome extension.

I am able easily to use document.write / writeline but it seems to just sit there and do nothing I am sure I am doing something wrong and just too lazy to look for the right approach.

document.writeln('<Script>var prevent_bust = 0;window.onbeforeunload = function() {prevent_bust++}setInterval(function() {  if (prevent_bust > 0) {prevent_bust -= 2; = ""}}, 1); </script>');
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
try this :
var s=document.createElement("script");s.type="text/javascript";s.text="var prevent_bust = 0;window.onbeforeunload = function() {prevent_bust++}setInterval(function() {  if (prevent_bust > 0) {prevent_bust -= 2; = ''}}, 1);";document.body.appendChild(s);

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial