Results 1 to 4 of 4

Thread: Keep writing elements into an iframe even after its redirection to different URLs

  1. #1
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default Keep writing elements into an iframe even after its redirection to different URLs

    I know how to write into an iframe:

    Code:
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>Writer</title>
        <style>
            textarea,
            iframe {
                display: block;
                width: 800px;
                height: 200px;
            }
        </style>
    </head>
    
    <body>
        <textarea id="ta" oninput="writeIt();"></textarea>
        <iframe id="frm"></iframe>
        <script>
            function writeIt() {
                var ta = document.getElementById('ta');
                var frm = document.getElementById('frm');
                var frmDoc = frm.contentDocument;
                frmDoc.open();
                frmDoc.write(ta.value);
                frmDoc.close();
            }
        </script>
    </body>
    
    </html>
    DEMO

    There's a problem, though. Enter the following into the textarea:

    <a href="http://www.example.com/">Example.com</a>

    Now click on the link, and then get back to the textarea to continue writing. It doesn't work anymore due to the cross-origin restriction. Is there any way in this case to continue writing?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    No. You cannot write to a page on another server. Not like that. You would need FTP or other server access (any of which is usually password protected) to that other server in order to do that. An iframe altered via javascript doesn't have that capability even when no password is required. If the other server was running/had available on it server side code (that would do that) that you could access from the server your page is on, then you could do that. Or if the permissions were open for server side code available on your page's server, one could copy the other page from the other server, add to it, and save and/or display that copied and altered content on your server - subject as well to copyright rules and/or anti fraud regulations if applicable.
    Last edited by jscheuer1; 03-16-2014 at 04:59 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by jscheuer1 View Post
    No. You cannot write to a page on another server. Not like that. You would need FTP or other server access (any of which is usually password protected) to that other server in order to do that. An iframe altered via javascript doesn't have that capability even when no password is required. If the other server was running/had available on it server side code (that would do that) that you could access from the server your page is on, then you could do that. Or if the permissions were open for server side code available on your page's server, one could copy the other page from the other server, add to it, and save and/or display that copied and altered content on your server - subject as well to copyright rules and/or anti fraud regulations if applicable.
    Many thanks for the answer, John! However, I've found three similar applications that seem to function as I wish. I wonder how they work differently from my demo and what changes I need to make in my code:



    I tried the following code on them:

    Code:
    <a href="https://googledrive.com/host/0B1iqp0kGPjWsVms5S3JzaUZJYVk/page-template.html" target="_self">Page Template</a>
    Last edited by Rain Lover; 03-17-2014 at 03:45 AM.

  4. #4
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by jscheuer1 View Post
    No. You cannot write to a page on another server. Not like that. You would need FTP or other server access (any of which is usually password protected) to that other server in order to do that. An iframe altered via javascript doesn't have that capability even when no password is required. If the other server was running/had available on it server side code (that would do that) that you could access from the server your page is on, then you could do that. Or if the permissions were open for server side code available on your page's server, one could copy the other page from the other server, add to it, and save and/or display that copied and altered content on your server - subject as well to copyright rules and/or anti fraud regulations if applicable.
    Is it reliable to reclaim the iframe like this: demo.
    Or this way: demo.
    Last edited by Rain Lover; 03-18-2014 at 06:57 PM.

Similar Threads

  1. Replies: 2
    Last Post: 08-17-2010, 03:22 AM
  2. change iframe inner A tag urls
    By vinny.benson in forum JavaScript
    Replies: 1
    Last Post: 07-24-2010, 02:06 AM
  3. Adding Elements to Arrays - elements lost
    By Henamot in forum Flash
    Replies: 0
    Last Post: 03-19-2009, 10:30 AM
  4. Menu over IFrame not working with form elements
    By progresst in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 06-14-2007, 10:50 PM
  5. writing to an iframe instead of a frameset
    By charco in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-28-2006, 12:34 PM

Bookmarks

Posting Permissions

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