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
    Jul 2012
    Location
    United Kingdom
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to set part of iframe src dynamically?

    Hi all,

    i am calling a url via an iframe which is a jre application.. in the url the is parts which im trying to make dynamic so i can set them via a javascript file?

    Is this possible so as an example i have:

    Code:
    <iframe src="http://myname/test/frmservlet?config=test&FORM=FORMNUMBER.fmx&userid=USERNAME/USERNAME@DATABASE" width="100%" height="100%"></iframe>
    Of which im trying to me "FORMNUMBER, USERNAME and database" all dynamic bits of the src as they may be different..

    can anyone help me?

    Matt

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,525
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Code:
    <html>
    ...
    <body>
    ...
    <iframe id="zamboni" style="width: 100%; height: 100%;"></iframe>
    ...
    <script type="text/javascript">
    var formnumber = 7731; // or wherever you get this from
    var username = "Harry Houdini";
    var database = "topSecret.mdb";
    
    // make sure the values can be used in a URL:
    var encFormnumber = encodeURIComponent( formnumber + ".fmx" );
    var encUserid = encodeURIComponent( username + "/" + username + "@" + database );
    
    var frm = document.getElementById("zamboni");
    frm.src = "http://myname/test/frmservlet?config=test&FORM=" + encFormnumber
            + "&userid=" + encUserid;
    </script>
    </body>
    </html>
    Yes, put the JS just before the </body> and after the <iframe>.
    Last edited by Old Pedant; 02-04-2013 at 10:28 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Mattlav (02-04-2013)

  • #3
    New to the CF scene
    Join Date
    Jul 2012
    Location
    United Kingdom
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by Old Pedant View Post
    Code:
    <html>
    ...
    <body>
    ...
    <iframe id="zamboni" style="width: 100%; height: 100%;"></iframe>
    ...
    <script type="text/javascript">
    var formnumber = 7731; // or wherever you get this from
    var username = "Harry Houdini";
    var database = "topSecret.mdb";
    
    // make sure the values can be used in a URL:
    var encFormnumber = encodeURIComponent( formnumber + ".fmx" );
    var encUserid = encodeURIComponent( username + "/" + username + "@" + database );
    
    var frm = document.getElementById("zamboni");
    frm.src = "http://myname/test/frmservlet?config=test&FORM=" + encFormnumber
            + "&userid=" + encUserid;
    </script>
    </body>
    </html>
    Yes, put the JS just before the </body> and after the <iframe>.
    thanks so much.. it worked my brain was having a confused moment!


  •  

    Posting Permissions

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