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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Iframe getElementsByTagName() Works on Local File but not External

    I am new to DOM scripting, and I can not find documentation on this ... The following script never completes the getElementsByTagName("A") call if the "content" frame is loaded with a live site like www.google.com or www.dictionary.com, etc ... IF I take the same sites, and copy the source to a local file and then use that file in the frame, then the call works fine.

    ===== Page Follows =====>

    <html><head><script type="text/javascript">

    function filter()
    {
    var output = document.getElementById("output").contentDocument;
    if( output ) { output.write( "output found<BR>\n" ); }

    var content = document.getElementById("content").contentDocument;
    if( content ) { output.write( "content found<BR>\n" ); }

    var obj = content.getElementsByTagName("A");

    output.write( "Tags Found!<BR>" );

    for( var i=0;i<obj.length;i++)
    {
    output.write( "_<BR>" );
    }

    output.write( "Tags Iterated!<BR>" );
    return 0;
    }

    </script></head><body>

    <a onclick="filter();">filter</a>

    <div id="out">
    <iframe name="output" id="output" frameborder="2" height=100 width=100% scrolling=auto>
    </iframe>
    </div>

    <div id="cntnt">
    <iframe name="content" id="content" frameborder="0" src="http://www.google.com/" height=100% width=100% scrolling=auto>
    </iframe>
    </div>

    </body></html>

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    It's the security model of JavaScript that does that - it only gives access to documents originating from the same domain. This is called the Same Origin Policy.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I see, and thank you! Ultimately, I can get the script inlined into pages on the site I am concerned with, but I have a couple o questions ...

    1. Can it be subverted? In this case to implement a generic filter on external pages.

    2. If I host a script on a remote server, but include it in files on the server in question, will that work?


  •  

    Posting Permissions

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