SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2004
    0 Post(s)
    0 Thread(s)

    Find/Replace on Javascript Greasemonkey Script not working


    I'm stuck on a javscript file used as a Greasemonkey script to rewrite some content on a web application I use at work.

    Previously posted on, but posting here as no reply there since that forum seems to be rarely used and is full of spam.

    I'm trying to change the size of a pop up window.

    The size is defined in a script tag:

    Code JavaScript:
    <script language="JavaScript">
    var temp ='/Sostenuto/Chameleon/Templates/EN/memo_popup.htm','Chameleon','width=400,height=350,status=no,resizable=no,scrollbars=yes,top=200,left=200,alwaysRaised=yes');

    I have tried this to do the change (there is only one instance of width=400 so it's not a global replace):

    Code JavaScript:
    var cells = document.getElementsByTagName('script');
    for (var i = 0; i < cells.length; i++) {
    		john = cells[i].innerHTML;
    		john = john.replace('width=400', 'width=800');
    		cells[i].innerHTML = john;

    But the replace is not firing.

    I have debugged via the "john" alert and can see it contains the text I want to replace, and when I output the value of "john" I can see that it contains width=800. However, the javascript doesn't seem to recognise it when the pop up window opens. Is it because javascript needs to have the value hard coded in the HTML so it picks it up when the page loads, and won't handle it being rewritten in the background via the GM script?

    Any advice much appreciated.


  2. #2
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    1 Post(s)
    0 Thread(s)
    I've never worked with Greasemonkey, so maybe I should be shutting my fat mouth, but it looks like you're basic premise wouldn't work. You're trying to grab the script via a DOM method, but change its contents before it runs. However, if the script is accessible via, say, getElementsByTagName, then the browser has already executed the script, hasn't it?

    I'm the web overlord for Graphic Business Systems


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts