Results 1 to 3 of 3

This is a discussion on Chrome content scripts within the Plugins Development section, part of the Chrome Plugins category: Hi, I tried to use a content script to add some text at the beginning of the html page for ...


  1. #1
    mack is offline Junior Member
    Join Date
    Aug 2009
    Location
    Canada
    Posts
    3

    Default Chrome content scripts

    Hi,

    I tried to use a content script to add some text at the beginning of the html page for a specific web page.

    In foo.js:

    document.write('Hello World!')

    which doesn't work;

    However, by following the "official" Chrome sample, I am able to change the first picture on the page:

    document.images[0].src = "http://icanhascheezburger.files.wordpress.com/2007/01/i-can-has-cheezburger.jpg"
    document.images[0].style.height = "auto"

    It seems the same DOM to me. Any ideas why document.write won't work?

    Thanks!

  2. #2
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    document.write is always a pretty sketchy function when using it on a page that wasn't entirely rendered by your JavaScript. It's best to either adjust the innerHTML of something, or make a new page element and insert it where you want it. You can get somewhat of an idea of the latter here. However you'll also need the document.createElement("elementName") function and potentially the document.createTextNode("text") function, which I don't see listed there.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  3. #3
    ocbaker is offline Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Default

    I have to say document.write has NEVER worked for me. If I was you I would completely avoid it, and I totally agree with Waha.

    Google Wave Developer

    goto my Hotmail notifier extension Here

Similar Threads

  1. Chrome Application Shortcuts - Extensions & User Scripts
    By StevePaul in forum Chrome Tips & Tricks
    Replies: 4
    Last Post: 07-08-2009, 07:25 PM
  2. User Scripts & Extensions
    By Luc VN in forum Chrome Plugins
    Replies: 5
    Last Post: 06-05-2009, 04:16 PM
  3. content script problem..
    By Gaurang033 in forum Chrome Plugins
    Replies: 0
    Last Post: 06-01-2009, 10:30 AM
  4. AutoHotKey scripts for Chrome
    By sridhar in forum Chrome Plugins
    Replies: 0
    Last Post: 09-10-2008, 11:15 AM

Tags for this Thread

Posting Permissions

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