Get your own customer support community
 

Some hints for Assignment 04

There are 3 different document objects that you should work with them in your javascript code for handling the page load event:
1) Browser document object
2) Sidebar document object
3) Document object of the active tab

The following snippet shows all of them:

onPageLoad: function(aEvent) {
var doc = aEvent.originalTarget; // doc is document that triggered "onload" event
var sidebardoc = document.getElementById("sidebar").contentDocument;
var anchorTags = doc.getElementsByTagName("a");
// Do something
}

In the above code, document is number 1 in the list; doc is number 3 and sidebardoc is number 2.

For example, you can define a container in your sidebar code using:

<html:div>
</html:div>

And then access it in the onPageLoad function using:

var container = sidebardoc.getElementById("container");

=============================

For adding links to your container, you should generate html:a elements. Since we want the links to be opened in the active tab and not in the side bar we should set the target to _content. The most important thing about generating links is that they should be generated under the xhtml namespace; otherwise they won't work. This snippet shows how to do this:

var oLink = sidebardoc.createElementNS("http://www.w3.org/1999/xhtml", "html:a");
oLink.setAttribute("href", "http://www.example.com/");
oLink.setAttribute("target", "_content");
container.appendChild(oLink);

=============================

Since I had to create the extension several times after each modification, I created a windows .bat file to automate this. Here is my script:

set path=%path%;c:\program files\7-Zip
cd chrome
7z a -tzip linksextractor.jar * -r -mx=0

cd ..
7z a -tzip linksextractor.xpi chrome.manifest install.rdf chrome/linksextractor.jar -r -mx=9

You need to download 7z if you want to use this script.

=============================

You can access browser's URL bar with the following snippet:

var urlbar = document.getElementById('urlbar')

For example, I can find the URL that is typed there by urlbar.value

This is helpful if you want to distinguish between onload events that are fired after iframe loads or main content load (although it's not asked in the assigment).
 
happy I’m happy
Inappropriate?
1 person likes this idea

User_default_medium