Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post

    innerHTML - get tag names?

    Hey,

    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:

    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!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Code:
    var ifrDoc = top.frames['iView'].document;
    for (var i=0;i<ifrDoc.links.length;i++){
       //there are <a> tags
       alert(ifrDoc.links[i].href);
    }
    for (var j=0;j<ifrDoc.images.length;j++){
       //there are <img> tags
       alert(ifrDoc.images[j].src)
    }

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    thanks! that's worked perfectly!!

    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...

    Code:
    thelink = ifrDoc.links[i].href;
    thelink = thelink.replace(/(href\s*=\s*.)[^*]*(\*\*\*)/, "$1$2");
    any further ideas? thank you very much!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    var thelink = ifrDoc.links[i].href;
    thelink = thelink.substr(thelink.lastIndexOf('/')+1);
    Hope that helps!

    Happy coding!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •