Using a variable in the src attribute of iframe

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dany P. Wu

    #1

    Using a variable in the src attribute of iframe

    Hi everyone,

    I've finally figured out what I actually want to do with my website, let's
    hope this time I can explain it better.

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

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

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

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

    I am assuming after I clicked the link from the opening page the variable
    "content" now contains "sub_contact.ht ml". 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="no">

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

    Can someone please tell me how I can achieve this? I'm very new in web
    scripting/programming.

    Thanks for the answers so far and any further suggestions would be greatly
    appreciated.

    Cheers,
    Dany.


  • Michael Winter

    #2
    Re: Using a variable in the src attribute of iframe

    Dany P. Wu wrote on 17 Nov 2003:
    [color=blue]
    > Hi everyone,
    >
    > I've finally figured out what I actually want to do with my
    > website, let's hope this time I can explain it better.
    >
    > The opening page of the website has a bunch of links that look
    > somewhat like:
    >
    > <a href="geninfo.h tml?sub_contact .html">
    >
    > The page geninfo.html contains an inline frame called "frame"
    > and has a short script like this:
    >
    > <!--
    > var temp=window.loc ation.split("?" );
    > var content=temp[1]
    > //-->
    >
    > I am assuming after I clicked the link from the opening page the
    > variable "content" now contains "sub_contact.ht ml". 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="no">
    >
    > but that's obviously wrong since it didn't work.
    >
    > Can someone please tell me how I can achieve this? I'm very new
    > in web scripting/programming.
    >
    > Thanks for the answers so far and any further suggestions would
    > be greatly appreciated.[/color]

    If you aren't going to add any other parameters to the URL (ever),
    then you could simply do:

    var content = window.location .search.substr( 1 );

    The substr( 1 ) call simply strips the question mark from the search
    property, which returns everything from the question mark onwards in
    a URL.

    However, if you do plan on adding other parameters, then it would be
    better to do something like:

    // Create an array of parameters passed to the page
    // Ampersands (&) should be used to separate name/value pairs
    var parameters = window.location .search.substr( 1 ).split( '&' );
    var content = parameters[0];

    Hope that helps,
    Mike

    --
    Michael Winter
    M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)

    Comment

    Working...