Tuesday, September 27, 2005

IE Html Code Util

Just checking the last release of the Developer Toolbar for Internet Explorer, I noticed that something already provided by Firefox´s one was missing. It consists on highligting the HTML code on a new div object created in the document context of the page you are navingating in which renders the text selected.

It gets useful to view some html code pieces without opening entire code page.

Item on the context menu needs to be included by opening windows registry and linking a html page hosted anywhere on your computer.

ScreenShot 1

Simple code,




oWindow = window.external.menuArguments

stHtmlScript = "function Ocultar(){document.getElementById('MiDiv').style.visibility='hidden';}";
oWindow.execScript(stHtmlScript);


oDocument = oWindow.document

oSelect = oDocument.selection
oSelectRange = oSelect.createRange()
//' TENEMOS EL TEXTO SELECCIONADO.
sNewText = oSelectRange.htmlText
sNewText2 = oSelectRange.text



if (oDocument.getElementById("MiDiv"))

{
midiv = oDocument.getElementById("MiDiv")
midiv.style.visibility = "visible"
midiv.style.left = oSelectRange.offsetLeft
midiv.style.top=oSelectRange.offsetTop + 15

miText = oDocument.getElementById("miTextArea")
miText.value = oSelectRange.htmlText
}

else
{
dv = oDocument.createElement("div")
dv.id = "MiDiv";
dv.style.position="absolute"
dv.style.visibility="visible"
dv.style.left = oSelectRange.offsetLeft
dv.style.top=oSelectRange.offsetTop + 15
dv.style.width=300
dv.style.height=100
dv.style.backgroundColor= "#FFFF00"

var miLink = oDocument.createElement("A")
miLink.href = "javascript:Ocultar()" //=
myImg=oDocument.createElement("IMG");
myImg.src = "http://www.meiga.info/images/cerrar.gif"
myImg.align = "center";
myImg.border= 0;
myImg.alt="Cerrar";
miLink.appendChild(myImg);

var miDivBr = oDocument.createElement("DIV")
miDivBr.innerHTML = "< BR >"


var miText = oDocument.createElement("TEXTAREA")
miText.id = "miTextArea"
miText.value = oSelectRange.htmlText
miText.style.width = "300"
miText.style.height = "150"
miText.style.align = "center"
miText.style.backgroundColor= "#D4D4D4"


oDocument.body.appendChild(dv)
dv.appendChild(miLink)
dv.appendChild(miDivBr)
dv.appendChild(miText)

}

0 Comments:

Post a Comment

<< Home