append html elements to DOM by background script

1,953 views
Skip to first unread message

moshe2b

unread,
Aug 10, 2011, 3:26:13 AM8/10/11
to Chromium-extensions
Hi,
I want to append the same html elements to the current TAB document
DOM.
I want these html extended elements to live "forever", so I want to
built them once, and append them on every page load by the content
script.
I was thinking to place the createElement commends at the background
page.
Then for every web page load, I want the content script to
communicate with the background script, so it will append them to the
current TAB document DOM.
Is that good practice?
My problem is that I don’t know how to append html elements to the DOM
from the background page.
Can you please help?

Boris Smus

unread,
Aug 11, 2011, 12:24:36 PM8/11/11
to moshe2b, Chromium-extensions
Hi Moshe,

You can modify the current tab by injecting javascript into it using content scripts or programmatic injection (executeScript). See http://code.google.com/chrome/extensions/content_scripts.html for more info about that.

Then you can communicate between the background page and content script with message passing APIs: http://code.google.com/chrome/extensions/messaging.html

Hope this helps,
- Boris


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


moshe2b

unread,
Aug 11, 2011, 12:53:26 PM8/11/11
to Chromium-extensions
You are missing my point or I'm missing some basic understanding:
When the user will request a URL, the Injected js will run and
generate my extended html elements.
This will happen again and again for every new URL the user will go
to.
I want to avoid it !!
I want to create my HTML elements once and to show them to the user on
button click event.
My interface is more then a simple div and it takes time to create -
it uses some data from the server and it interact with the user, and
so on and on..
This is my motivation for my request - to keep my interface alive as
long as the chrome window is open - like the background page, and not
as long as the user is in the same URL.
Many thanks,
Moshe

On Aug 11, 7:24 pm, Boris Smus <s...@chromium.org> wrote:
> Hi Moshe,
>
> You can modify the current tab by injecting javascript into it using content
> scripts or programmatic injection (executeScript). Seehttp://code.google.com/chrome/extensions/content_scripts.htmlfor more info
> about that.
>
> Then you can communicate between the background page and content script with
> message passing APIs:http://code.google.com/chrome/extensions/messaging.html
>
> Hope this helps,
> - Boris
>
>
>
>
>
>
>
> On Wed, Aug 10, 2011 at 12:26 AM, moshe2b <mosh...@gmail.com> wrote:
> > Hi,
> > I want to append the same html elements to the current TAB document
> > DOM.
> > I want these html extended elements to live "forever", so I want to
> > built them once, and append them on every page load by the content
> > script.
> > I was thinking to place the createElement commends at the background
> > page.
> > Then for every web page load, I want the  content script to
> > communicate with the background script, so it will append them to the
> > current TAB document DOM.
> > Is that good practice?
> > My problem is that I don’t know how to append html elements to the DOM
> > from the background page.
> > Can you please help?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org.

Boris Smus

unread,
Aug 11, 2011, 1:27:13 PM8/11/11
to moshe2b, Chromium-extensions
You can generate the HTML you want once, in the background page. Then you can send it to the tab page using the messaging API.

- Boris

To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

nasiruddin.s...@gmail.com

unread,
Apr 13, 2018, 5:13:23 AM4/13/18
to Chromium-Extensions-Announce, mos...@gmail.com

Hello did you succeeded i am facing same issue and i have to render full html page in it and i have build extension using AngularJs, 
That html page contents Table and button which are live reloaded from server and have router in it to route multiple pages.  
Reply all
Reply to author
Forward
0 new messages