View Full Version : innerHTML - get tag names?

05-05-2004, 02:44 PM

I am trying to get the contents of an iFrame using the innerHTML - I need to look at all the tags for example..

....get the contents of the iFrame (innerHTML) and see if there are any "a" tags or "img" tags.

(<a href> and <img> tags)

If there are I want to do things with them - thats not a problem - its just the looking to see if the tags are there. I've tried using the following code:

var cursor = iView.document.innerHTML.createRange();
var element = cursor.parentElement();

but it doesnt like that. I basically need to get acess to the tag names...

any help is much appreciated!

05-05-2004, 02:51 PM
var ifrDoc = top.frames['iView'].document;
for (var i=0;i<ifrDoc.links.length;i++){
//there are <a> tags
for (var j=0;j<ifrDoc.images.length;j++){
//there are <img> tags

05-05-2004, 03:14 PM
thanks! that's worked perfectly!! :D

might you be able to help me with the next part?
I now need to replace the url - as it adds an absolute part when I dont want that...

so the url might be something like

<a href="homer.htm"> but IE iFrame adds the path of the page to it..

<a href="c://file//folder/etc/homer.htm"> (or similar!)

I have tried the following string to replace the path using your code when it finds an "a" tag...

thelink = ifrDoc.links[i].href;
thelink = thelink.replace(/(href\s*=\s*.)[^*]*(\*\*\*)/, "$1$2");

any further ideas? thank you very much!

05-05-2004, 09:55 PM
var thelink = ifrDoc.links[i].href;
thelink = thelink.substr(thelink.lastIndexOf('/')+1);

Hope that helps!

Happy coding! :)