[Project_owners] javascript on a page

InBasic inb.cor at gmail.com
Fri Jan 11 13:14:40 PST 2008


Hi
Use this for adding HTML/JS/PHP/...:

data="\
<script type='text/javascript'>\n\
    alert('Alert from JS')\n\
</script>\n\
<b>Text from HTML & add some PHP in this way...</b>\n\
";
addHTML(data);



function addHTML (html) {
    var document=gBrowser.selectedBrowser.contentDocument ;
    if (document.all)
        document.body.insertAdjacentHTML ('beforeEnd', html);
    else if (document.createRange) {
        var range = document.createRange();
        range.setStartAfter(document.body.lastChild);
        var cFrag = range.createContextualFragment(html);
        document.body.appendChild(cFrag);
    }
    else if (document.layers) {
        var X = new Layer(window.innerWidth);
        X.document.open();
        X.document.write(html);
        X.document.close();
        X.top = document.height;
        document.height += X.document.height;
        X.visibility = 'show';
    }
}


InBasic.



On Jan 11, 2008 8:31 PM, joe ertaba <belaviyo at gmail.com> wrote:

> Thank Eric,
> is it possible to add some other codes like php or html code to a page too
> ?
>
>
> On Jan 10, 2008 4:49 PM, Eric H. Jung < eric.jung at yahoo.com > wrote:
>
> >
> > --- joe ertaba < belaviyo at gmail.com> wrote:
> >
> > > hi,
> > >
> > > i need to add some javascript function to some especial pages;
> > > i want to for example show a alert('...') when user click on especial
> > link
> > > on page
> >
> > I assume you mean from an extension and not on your project page :)
> > If so, then wait for the page to load, get the document content, and:
> >
> > var s = document.createElement("script");
> > s.setAttribute("type", "text/javascript");
> > s.appendChild(document.createTextNode("alert('hello world');"));
> > document.getElementsByTagName["head"][0].appendChild(s); // won't work
> > if document has no HEAD
> >
> >
> > _______________________________________________
> > Project_owners mailing list
> > Project_owners at mozdev.org
> > https://www.mozdev.org/mailman/listinfo/project_owners
> >
>
>
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> https://www.mozdev.org/mailman/listinfo/project_owners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.mozdev.org/pipermail/project_owners/attachments/20080112/415fe51f/attachment.html 


More information about the Project_owners mailing list