dynamic iframes...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frances

    dynamic iframes...

    I need to replace iframes acc. to what option user chooses in a sel
    obj.. but figured have to load a blank iframe when pg loads so I can
    replace it.. (iframe gets put in a pre-existing div..) this is
    approach.. I'm having some problems and would appreciate some help..
    thank you very much...

    var selItem;
    var ifrCurr;
    var div = document.getEle mentById("divPr icing");
    // this var not being read inside functions..
    // (even if I take out 'var' from declaration..)

    function currIF() { // to load a blank iframe..
    ifrCurr = document.create Element("iframe ");
    ifrCurr.src = 'iframes/blank.html';
    //div.appendChild (ifrCurr); // ****** var not being read...

    document.getEle mentById("divPr icing").appendC hild(ifrCurr);
    // errror on this line
    // is null or not an obj... (??)
    // no problem w/this line in below function..
    }
    window.onload=c urrIF();


    function pricing() { // load iframes dynamically..
    selItem = document.getEle mentById("produ ct").value;
    var ifr = document.create Element("iframe ");
    ifr.src = 'iframes/' + selItem + '.html';

    document.getEle mentById("divPr icing").appendC hild(ifr);
    // works fine here....

    // div.appendChild (ifr); // ******* var not being read...

    // document.getEle mentById("divPr icing").replace Child(ifr,ifrCu rr);
    // can't use this line yet b/c problems w/function above....
    }

    thank you very much........ Frances

  • Frances

    #2
    Re: dynamic iframes...

    Frances wrote:[color=blue]
    > I need to replace iframes acc. to what option user chooses in a sel
    > obj.. but figured have to load a blank iframe when pg loads so I can
    > replace it.. (iframe gets put in a pre-existing div..) this is
    > approach.. I'm having some problems and would appreciate some help..
    > thank you very much...
    >
    > var selItem;
    > var ifrCurr;
    > var div = document.getEle mentById("divPr icing");
    > // this var not being read inside functions..
    > // (even if I take out 'var' from declaration..)
    >
    > function currIF() { // to load a blank iframe..
    > ifrCurr = document.create Element("iframe ");
    > ifrCurr.src = 'iframes/blank.html';
    > //div.appendChild (ifrCurr); // ****** var not being read...
    >
    > document.getEle mentById("divPr icing").appendC hild(ifrCurr);
    > // errror on this line
    > // is null or not an obj... (??)
    > // no problem w/this line in below function..
    > }
    > window.onload=c urrIF();
    >
    >
    > function pricing() { // load iframes dynamically..
    > selItem = document.getEle mentById("produ ct").value;
    > var ifr = document.create Element("iframe ");
    > ifr.src = 'iframes/' + selItem + '.html';
    >
    > document.getEle mentById("divPr icing").appendC hild(ifr);
    > // works fine here....
    >
    > // div.appendChild (ifr); // ******* var not being read...
    >
    > // document.getEle mentById("divPr icing").replace Child(ifr,ifrCu rr);
    > // can't use this line yet b/c problems w/function above....
    > }
    >
    > thank you very much........ Frances[/color]


    this will not work, as users could change iframe even after they have
    already chosen one.. I need to detect what iframe is loaded (i.e., what
    FILE is loaded in iframe..) in order to replace it.. again thank you
    very much...


    Comment

    • web.dev

      #3
      Re: dynamic iframes...


      Frances wrote:[color=blue]
      > I need to replace iframes acc. to what option user chooses in a sel
      > obj.. but figured have to load a blank iframe when pg loads so I can
      > replace it.. (iframe gets put in a pre-existing div..) this is
      > approach.. I'm having some problems and would appreciate some help..
      > thank you very much...
      >
      > var selItem;[/color]

      Do you still need selItem to be a global variable? It seems you're
      only using it in your pricing() function.
      [color=blue]
      > var ifrCurr;[/color]

      var ifrCurr = null;
      [color=blue]
      > var div = document.getEle mentById("divPr icing");
      > // this var not being read inside functions..
      > // (even if I take out 'var' from declaration..)
      >
      > function currIF() { // to load a blank iframe..
      > ifrCurr = document.create Element("iframe ");
      > ifrCurr.src = 'iframes/blank.html';
      > //div.appendChild (ifrCurr); // ****** var not being read...
      >
      > document.getEle mentById("divPr icing").appendC hild(ifrCurr);
      > // errror on this line
      > // is null or not an obj... (??)
      > // no problem w/this line in below function..
      > }
      > window.onload=c urrIF();[/color]

      I believe you don't need to load a blank iframe. So you can remove
      that line and the above function.
      [color=blue]
      >
      >
      > function pricing() { // load iframes dynamically..
      > selItem = document.getEle mentById("produ ct").value;
      > var ifr = document.create Element("iframe ");
      > ifr.src = 'iframes/' + selItem + '.html';
      >
      > document.getEle mentById("divPr icing").appendC hild(ifr);
      > // works fine here....
      >
      > // div.appendChild (ifr); // ******* var not being read...
      >
      > // document.getEle mentById("divPr icing").replace Child(ifr,ifrCu rr);
      > // can't use this line yet b/c problems w/function above....
      > }
      >
      > thank you very much........ Frances[/color]

      You should code defensively. Ensure that you actually have an object.

      function replaceIFrame()
      {
      if(div)
      {
      var selItem = document.getEle mentById("produ ct").value;
      var newifr = document.create Element("iframe ");
      newifr.src = 'iframes/' + selItem + '.html';

      if(ifrCurr == null)
      {
      ifrCurr = div.appendChild (newifr);
      }
      else
      {
      div.replaceChil d(newifr, ifrCurr);
      ifrCurr = newifr;
      }
      }
      }

      Comment

      • Frances

        #4
        Re: dynamic iframes...

        web.dev wrote:[color=blue]
        > Frances wrote:
        >[color=green]
        >>I need to replace iframes acc. to what option user chooses in a sel
        >>obj.. but figured have to load a blank iframe when pg loads so I can
        >>replace it.. (iframe gets put in a pre-existing div..) this is
        >>approach.. I'm having some problems and would appreciate some help..
        >>thank you very much...
        >>
        >>var selItem;[/color]
        >
        >
        > Do you still need selItem to be a global variable? It seems you're
        > only using it in your pricing() function.
        >
        >[color=green]
        >>var ifrCurr;[/color]
        >
        >
        > var ifrCurr = null;
        >
        >[color=green]
        >>var div = document.getEle mentById("divPr icing");
        >> // this var not being read inside functions..
        >> // (even if I take out 'var' from declaration..)
        >>
        >>function currIF() { // to load a blank iframe..
        >>ifrCurr = document.create Element("iframe ");
        >>ifrCurr.src = 'iframes/blank.html';
        >>//div.appendChild (ifrCurr); // ****** var not being read...
        >>
        >>document.getE lementById("div Pricing").appen dChild(ifrCurr) ;
        >> // errror on this line
        >> // is null or not an obj... (??)
        >> // no problem w/this line in below function..
        >>}
        >> window.onload=c urrIF();[/color]
        >
        >
        > I believe you don't need to load a blank iframe. So you can remove
        > that line and the above function.
        >
        >[color=green]
        >>
        >>function pricing() { // load iframes dynamically..
        >> selItem = document.getEle mentById("produ ct").value;
        >> var ifr = document.create Element("iframe ");
        >> ifr.src = 'iframes/' + selItem + '.html';
        >>
        >> document.getEle mentById("divPr icing").appendC hild(ifr);
        >> // works fine here....
        >>
        >>// div.appendChild (ifr); // ******* var not being read...
        >>
        >>// document.getEle mentById("divPr icing").replace Child(ifr,ifrCu rr);
        >> // can't use this line yet b/c problems w/function above....
        >> }
        >>
        >>thank you very much........ Frances[/color]
        >
        >
        > You should code defensively. Ensure that you actually have an object.
        >
        > function replaceIFrame()
        > {
        > if(div)
        > {
        > var selItem = document.getEle mentById("produ ct").value;
        > var newifr = document.create Element("iframe ");
        > newifr.src = 'iframes/' + selItem + '.html';
        >
        > if(ifrCurr == null)
        > {
        > ifrCurr = div.appendChild (newifr);
        > }
        > else
        > {
        > div.replaceChil d(newifr, ifrCurr);
        > ifrCurr = newifr;
        > }
        > }
        > }
        >[/color]

        thank you VERY MUCH, web.dev......:)

        following yr post this is what I have now..

        function pricing() {
        //if (div) {
        var div = document.getEle mentById("divPr icing");
        var selItem = document.getEle mentById("produ ct").value;
        var ifrCurr = null;
        var ifrNew = document.create Element("iframe ");
        ifrNew.src = 'iframes/' + selItem + '.html';

        if (ifrCurr == null) {
        ifrCurr = div.appendChild (ifrNew);
        } else {
        div.replaceChil d(ifrNew,ifrCur r);
        ifrCurr = ifrNew;
        }
        // }
        }

        but it still puts new iframe NEXT TO current one, not on top...

        (had to take out if(div) line, script did not work at all (did not load
        iframe at all) if I left it in... (??) have TONS of divs on this page,
        so probably don't need this.. (it detects whether or not there are any
        divs on page, right?)

        again many thanks.... Frances

        Comment

        • web.dev

          #5
          Re: dynamic iframes...


          Frances wrote:[color=blue]
          > web.dev wrote:[color=green]
          > > Frances wrote:
          > >[color=darkred]
          > >>I need to replace iframes acc. to what option user chooses in a sel
          > >>obj.. but figured have to load a blank iframe when pg loads so I can
          > >>replace it.. (iframe gets put in a pre-existing div..) this is
          > >>approach.. I'm having some problems and would appreciate some help..
          > >>thank you very much...
          > >>
          > >>var selItem;[/color]
          > >
          > >
          > > Do you still need selItem to be a global variable? It seems you're
          > > only using it in your pricing() function.
          > >
          > >[color=darkred]
          > >>var ifrCurr;[/color]
          > >
          > >
          > > var ifrCurr = null;
          > >
          > >[color=darkred]
          > >>var div = document.getEle mentById("divPr icing");
          > >> // this var not being read inside functions..
          > >> // (even if I take out 'var' from declaration..)
          > >>
          > >>function currIF() { // to load a blank iframe..
          > >>ifrCurr = document.create Element("iframe ");
          > >>ifrCurr.src = 'iframes/blank.html';
          > >>//div.appendChild (ifrCurr); // ****** var not being read...
          > >>
          > >>document.getE lementById("div Pricing").appen dChild(ifrCurr) ;
          > >> // errror on this line
          > >> // is null or not an obj... (??)
          > >> // no problem w/this line in below function..
          > >>}
          > >> window.onload=c urrIF();[/color]
          > >
          > >
          > > I believe you don't need to load a blank iframe. So you can remove
          > > that line and the above function.
          > >
          > >[color=darkred]
          > >>
          > >>function pricing() { // load iframes dynamically..
          > >> selItem = document.getEle mentById("produ ct").value;
          > >> var ifr = document.create Element("iframe ");
          > >> ifr.src = 'iframes/' + selItem + '.html';
          > >>
          > >> document.getEle mentById("divPr icing").appendC hild(ifr);
          > >> // works fine here....
          > >>
          > >>// div.appendChild (ifr); // ******* var not being read...
          > >>
          > >>// document.getEle mentById("divPr icing").replace Child(ifr,ifrCu rr);
          > >> // can't use this line yet b/c problems w/function above....
          > >> }
          > >>
          > >>thank you very much........ Frances[/color]
          > >
          > >
          > > You should code defensively. Ensure that you actually have an object.
          > >
          > > function replaceIFrame()
          > > {
          > > if(div)
          > > {
          > > var selItem = document.getEle mentById("produ ct").value;
          > > var newifr = document.create Element("iframe ");
          > > newifr.src = 'iframes/' + selItem + '.html';
          > >
          > > if(ifrCurr == null)
          > > {
          > > ifrCurr = div.appendChild (newifr);
          > > }
          > > else
          > > {
          > > div.replaceChil d(newifr, ifrCurr);
          > > ifrCurr = newifr;
          > > }
          > > }
          > > }
          > >[/color]
          >
          > thank you VERY MUCH, web.dev......:)
          >
          > following yr post this is what I have now..
          >[/color]

          Don't forget to include:

          var div = document.getEle mentById("divPr icing");
          [color=blue]
          > function pricing() {
          > //if (div) {
          > var div = document.getEle mentById("divPr icing");
          > var selItem = document.getEle mentById("produ ct").value;
          > var ifrCurr = null;
          > var ifrNew = document.create Element("iframe ");
          > ifrNew.src = 'iframes/' + selItem + '.html';
          >
          > if (ifrCurr == null) {
          > ifrCurr = div.appendChild (ifrNew);
          > } else {
          > div.replaceChil d(ifrNew,ifrCur r);
          > ifrCurr = ifrNew;
          > }
          > // }
          > }
          >
          > but it still puts new iframe NEXT TO current one, not on top...
          >
          > (had to take out if(div) line, script did not work at all (did not load
          > iframe at all) if I left it in... (??) have TONS of divs on this page,
          > so probably don't need this.. (it detects whether or not there are any
          > divs on page, right?)
          >
          > again many thanks.... Frances[/color]

          The if(div) statement is there to check if an object exists.

          Comment

          • km0ti0n

            #6
            Re: dynamic iframes...


            Concider this :


            var Banana = document.getEle mentById("Orang e");
            /*
            This has created var var called Banana.
            And stored to it a reference to an element with the id="Orange"
            */

            if( Banana )
            {
            /*
            If you reach this point there's an element on the page
            with an id="Orange";
            */
            }
            else
            {
            /*
            If you reach here there's no element on in the DOM
            with the id="Orange";
            */
            }


            OK so that's why webdev was used this

            function replaceIFrame()
            {
            var div = document.getEle mentById("divPr icing");
            if(div)
            { ...




            Comment

            Working...