paperlined.org
apps > bookmarklets > html
document updated 19 years ago, on Nov 25, 2005
drag_and_rename (216 characters)



// ----------------------------------------------------------------------------------
// Displays the HTML code associated with whatever section of a page is highlighted.
// Works with frames.
// 
// Pilfered from http://www.google.com/options/buttons.html
//
// Doesn't work inside frames which are from a separate domain than the outside from is from.
//
// Works:
// 	IE5.5
//	IE6.0
//
// Fails:
//	NS6
//
// ----------------------------------------------------------------------------------


// When no frames
q = (document.frames.length ? '' :
	document.selection.createRange().htmlText);

// An 'if' statement isn't needed here because if no frames exist, then
// document.frames.length will be 0, so the for-loop will never run,
// so the 'q' from above won't be overwritten.
//
// If this IS a framed document, then the above command won't fail, it will
// just return ''.

// When there are frames
for (i=0; i<document.frames.length; i++)
{
	q = document.frames[i].document.selection.createRange().htmlText;
	if(q != '')
		break;
}

// Display the results
if(q)
	alert(q);