Question

Hi i need help for an Firefox Plugin. With Javascript i want to change Links to a specified Website to iframes For Example:

<a href="www.example.com">Website-Sample</a>

I want to change to:

<Iframe src="www.example.com"></iframe>

Any Link on a Website to example.com should be an iframe.

Can anyone help? Thanks P.s. sorry for my bad english

Edit:

Now i have made a lite bit and now i am able to change a link ta an Iframe. But it changes only the first link on a site. Whath ist wrong?

var document = document.contentDocument;
var doc_bodies = document.getElementsByTagName('a');
for(var i = 0; i < doc_bodies.length; i++) 
{ 
if(doc_bodies[i].href.match('example')) {
var doc_body = doc_bodies[i];
var first_element = doc_body.firstChild;

var url_div = document.createElement("iframe");

url_div.scrolling = "no";
url_div.marginWidth = 0;
url_div.marginHeight = 0;
url_div.frameBorder = 1;
url_div.style.cssText = "width:400px;height:200px;border-radius:5px;left:0px;";
url_div.id = 'added-by-firefox-extension';
url_div.src = doc_bodies[i].href;


doc_bodies[i].parentNode.replaceChild(url_div, doc_bodies[i]);

}

}

Was it helpful?

Solution

I think i have solved the problem:

     var document = document.contentDocument;
var doc_bodies = document.getElementsByTagName('a');

var link_count = doc_bodies.length;
var i = 0;
do{


    if(doc_bodies[i].href.match('example')) {
        var doc_body = doc_bodies[i];
        var url_div = document.createElement("iframe");
        url_div.scrolling = "no";
        url_div.marginWidth = 0;
        url_div.marginHeight = 0;
        url_div.frameBorder = 1;
        url_div.style.cssText = "width:400px;height:200px;border-radius:5px;left:0px;-moz-box-shadow: 10px 19px 20px #7b8674; /* firefox */ box-shadow: 10px 19px 20px #7b8674;margin-bottom:10px";
        url_div.id = 'added-by-firefox-extension';
        url_div.src = doc_bodies[i].href;
        doc_bodies[i].parentNode.replaceChild(url_div, doc_bodies[i]);

        }
        else
        {
            i++;
        }


    }while( i < doc_bodies.length);

Now i have to include this in a Firefox Addon. If anyone could help, that would be great. Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top