Using a variable in the src attribute of iframe

Discussion in 'NZ Computing' started by Dany P. Wu, Nov 17, 2003.

  1. Dany P. Wu

    Dany P. Wu Guest

    Okay, last time I asked a question about HTML I just about got my head
    bitten off. Anyway, I'm game enough to try again in hope I'd get some useful
    comments.

    I've got a couple of pages which has a variable passed between them using
    Javascript.

    The opening page of the website has a bunch of links that look somewhat
    like:

    <a href="geninfo.html?sub_contact.html">

    The page geninfo.html contains an inline frame called "frame" and has a
    short script like this:

    <!--
    var temp=window.location.split("?");
    var content=temp[1]
    //-->

    I am assuming after I clicked the link from the opening page the variable
    "content" now contains "sub_contact.html". Am I correct?

    How can I use this variable in my iframe tag?

    I've tried this:

    <iframe name="frame" height="409" width="580" border="0" frameborder="0"
    src=content scrolling="auto">

    but that's obviously wrong since it didn't work.

    Can someone please tell me how I can achieve this? I have searched the web
    but none of them really show how I can achieve this. They have a lot of
    examples setting values of various controls on different frames of the same
    page, but not inline frames. This has really got me confused. Some
    assistance would be greatly appreciated.

    Cheers,
    Dany.
    Dany P. Wu, Nov 17, 2003
    #1
    1. Advertising

  2. Dany P. Wu

    Jay Guest

    Dany P. Wu wrote:

    > Okay, last time I asked a question about HTML I just about got my head
    > bitten off. Anyway, I'm game enough to try again in hope I'd get some
    > useful comments.
    >
    > I've got a couple of pages which has a variable passed between them using
    > Javascript.
    >
    > The opening page of the website has a bunch of links that look somewhat
    > like:
    >
    > <a href="geninfo.html?sub_contact.html">
    >
    > The page geninfo.html contains an inline frame called "frame" and has a
    > short script like this:
    >
    > <!--
    > var temp=window.location.split("?");
    > var content=temp[1]
    > //-->
    >
    > I am assuming after I clicked the link from the opening page the variable
    > "content" now contains "sub_contact.html". Am I correct?
    >
    > How can I use this variable in my iframe tag?
    >
    > I've tried this:
    >
    > <iframe name="frame" height="409" width="580" border="0" frameborder="0"
    > src=content scrolling="auto">
    >
    > but that's obviously wrong since it didn't work.
    >
    > Can someone please tell me how I can achieve this? I have searched the web
    > but none of them really show how I can achieve this. They have a lot of
    > examples setting values of various controls on different frames of the
    > same page, but not inline frames. This has really got me confused. Some
    > assistance would be greatly appreciated.


    Your 'src=content' isn't going to be interpreted as javascript, is it?
    How is the HTML interpreter to know what it is?

    I'm not sure of the exact answer but something like src=javascript:content
    or via a javascript function like src="javascript:eek:penit('content')" is
    going to have a better chance of working.
    Jay, Nov 17, 2003
    #2
    1. Advertising

  3. Dany P. Wu

    rob Guest

    "Dany P. Wu" <> wrote in message
    news:...
    > Okay, last time I asked a question about HTML I just about got my head
    > bitten off. Anyway, I'm game enough to try again in hope I'd get some

    useful
    > comments.
    >
    > I've got a couple of pages which has a variable passed between them using
    > Javascript.
    >
    > The opening page of the website has a bunch of links that look somewhat
    > like:
    >
    > <a href="geninfo.html?sub_contact.html">
    >
    > The page geninfo.html contains an inline frame called "frame" and has a
    > short script like this:
    >
    > <!--
    > var temp=window.location.split("?");
    > var content=temp[1]
    > //-->
    >
    > I am assuming after I clicked the link from the opening page the variable
    > "content" now contains "sub_contact.html". Am I correct?
    >
    > How can I use this variable in my iframe tag?
    >
    > I've tried this:
    >
    > <iframe name="frame" height="409" width="580" border="0" frameborder="0"
    > src=content scrolling="auto">
    >
    > but that's obviously wrong since it didn't work.
    >
    > Can someone please tell me how I can achieve this? I have searched the web
    > but none of them really show how I can achieve this. They have a lot of
    > examples setting values of various controls on different frames of the

    same
    > page, but not inline frames. This has really got me confused. Some
    > assistance would be greatly appreciated.
    >
    > Cheers,
    > Dany.
    >
    >


    Hi Dany,

    don't assume that I actually know what I'm talking about but....
    I reckon you may need to use Document.write (javascript) to combine the HTML
    and the javascript variable.
    So you might have something like this:

    <iframe name="frame" height="409" width="580" border="0" frameborder="0"
    scrolling="auto"

    <script language="JavaScript">
    <!--
    document.write "src=" & content & ">"
    //-->
    </script>

    I expect I've got some syntax wrong etc. but you get the idea.

    If you want to speak to some pretty knowledgeable people you could try the
    pviiwebdev newsgroup on forums.projectseven.com
    I have a wee lurk around there from time to time - they're a pretty friendly
    bunch.
    have fun
    rgds
    rob
    rob, Nov 17, 2003
    #3
  4. Dany P. Wu

    rob Guest

    by the way, I'd shy away from using frame as a name - it maybe a reserved
    word or some such.
    rob, Nov 17, 2003
    #4
  5. Dany P. Wu

    Mainlander Guest

    In article <>,
    says...
    > Okay, last time I asked a question about HTML I just about got my head
    > bitten off. Anyway, I'm game enough to try again in hope I'd get some useful
    > comments.
    >
    > I've got a couple of pages which has a variable passed between them using
    > Javascript.
    >
    > The opening page of the website has a bunch of links that look somewhat
    > like:
    >
    > <a href="geninfo.html?sub_contact.html">
    >
    > The page geninfo.html contains an inline frame called "frame" and has a
    > short script like this:
    >
    > <!--
    > var temp=window.location.split("?");
    > var content=temp[1]
    > //-->
    >
    > I am assuming after I clicked the link from the opening page the variable
    > "content" now contains "sub_contact.html". Am I correct?
    >
    > How can I use this variable in my iframe tag?
    >
    > I've tried this:
    >
    > <iframe name="frame" height="409" width="580" border="0" frameborder="0"
    > src=content scrolling="auto">
    >
    > but that's obviously wrong since it didn't work.
    >
    > Can someone please tell me how I can achieve this? I have searched the web
    > but none of them really show how I can achieve this. They have a lot of
    > examples setting values of various controls on different frames of the same
    > page, but not inline frames. This has really got me confused. Some
    > assistance would be greatly appreciated.


    Straight HTML contains nothing at all to do with variables. Your example
    would need to be rewritten to use Javascript to output the frame name in
    the place where you have shown the variable name.
    Mainlander, Nov 17, 2003
    #5
  6. Dany P. Wu

    Dany P. Wu Guest

    "rob" <> wrote in message
    news:bpbamq$s4j$...
    > Hi Dany,
    >
    > don't assume that I actually know what I'm talking about but....
    > I reckon you may need to use Document.write (javascript) to combine the

    HTML
    > and the javascript variable.
    > So you might have something like this:
    >
    > <iframe name="frame" height="409" width="580" border="0" frameborder="0"
    > scrolling="auto"
    >
    > <script language="JavaScript">
    > <!--
    > document.write "src=" & content & ">"
    > //-->
    > </script>
    >
    > I expect I've got some syntax wrong etc. but you get the idea.


    Thanks Rob, I figured it out when I got out of bed this morning and you're
    right, your syntax is wrong but the general idea of parsing the variable
    into the HTML tag is right on the spot!

    > If you want to speak to some pretty knowledgeable people you could try the
    > pviiwebdev newsgroup on forums.projectseven.com
    > I have a wee lurk around there from time to time - they're a pretty

    friendly
    > bunch.
    > have fun


    Thanks for that too.

    Cheers,
    Dany.
    Dany P. Wu, Nov 18, 2003
    #6
  7. In article <>,
    "Dany P. Wu" <> wrote:

    >How can I use this variable in my iframe tag?


    You need to use Dynamic HTML. That is to say, by making assignments to
    appropriate objects within the document, you can selectively replace
    content. Here's a quick-and-dirty working example I just threw together:

    <HTML>
    <HEAD><TITLE>IFRAME Test</TITLE>
    <BODY>
    <P>This text comes before.
    <P><IFRAME NAME="testframe" SRC="http://www.microsoft.com/" WIDTH=400
    HEIGHT=400>
    <P>This text comes after.
    <BUTTON ONCLICK="document.testframe.location =
    'http://www.apple.com'">Click Me</BUTTON>
    </BODY>
    </HTML>

    This initially loads up showing the Microsoft home page within the
    iframe. Click the "Click Me" button, and this is changed to the Apple
    home page.

    Anyway, that should give you the idea.
    Lawrence D¹Oliveiro, Nov 18, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ashjas
    Replies:
    8
    Views:
    1,223
  2. stunbunny

    IFRAME and Video

    stunbunny, Dec 3, 2007, in forum: General Computer Support
    Replies:
    0
    Views:
    743
    stunbunny
    Dec 3, 2007
  3. pratima
    Replies:
    2
    Views:
    2,062
    ProgTalk
    Feb 2, 2008
  4. eyal1234
    Replies:
    1
    Views:
    1,354
    sjk123
    Jul 22, 2008
  5. lebohang

    Printing all contents of Iframe

    lebohang, Mar 4, 2009, in forum: Software
    Replies:
    1
    Views:
    1,249
Loading...

Share This Page