set target frame for jumpURL function

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

    #1

    set target frame for jumpURL function

    Hi all

    I have done lots of VB programming, but am not familiar with JavaScript.

    Can anyone tell me how to do this ....?

    I have a JS file for a menu system called menu.js

    It contains the following function :

    this.jumpURL = function(url) {
    if(url) document.locati on.href = url;
    }

    I want to get the function to select the 'target' frame / page / etc
    depending on variables sent to the function.

    eg
    this.jumpURL = function(url, target) {
    if(url) target.location .href = url;

    If I then call the function jumpURL (www.abcd.com, InFrame1 )
    it should open the page in an inline frame named InFrame1

    For some reason I cannot grasp how to make this work.

    However, if I change it to :
    if(url) InFrame1.locati on.href = url;
    it works fine ( ie.. with the physical name of the frame in the statement ).

    SO.......How can I use a variable in place of "InFrame1" ?

    or do I need something along the lines of :

    if target = "InFrame1" then if(url) InFrame1.locati on.href = url;
    if target = "InFrame2" then if(url) InFrame2.locati on.href = url;
    if target = "InFrame3" then if(url) InFrame3.locati on.href = url;

    This would be the VB style of IF statement - I do not understand the JS
    structure yet.

    However, this would be very limiting meaning that I would need to modify the
    function in the menu.js file every time my html page was changed.

    My thanks and appreciation in advance for any assistance.

    DaveO



  • kaeli

    #2
    Re: set target frame for jumpURL function

    In article <d6i6pk$ih2$1@c tb-nnrp2.saix.net> , jsinvest@mweb.c o.za enlightened
    us with...[color=blue]
    > this.jumpURL = function(url, target) {
    > if(url) target.location .href = url;
    >[/color]

    this.jumpURL = function(url, target) {
    if (url) {
    if (!target) {
    // call the default frame "main" or something
    target = "main";
    }
    top.frames[target].document.locat ion.href = url;
    }
    }

    And do note that while vb comparisons and assignments both use the "=" sign,
    javascript uses "=" for assignment and "==" for comparisons. A little tip for
    you. ;)

    --
    --
    ~kaeli~
    With her marriage, she got a new name and a dress.



    Comment

    • DaveO

      #3
      Re: set target frame for jumpURL function

      Hi kaeli

      Many thanks for the info.

      However, is the line target = "main" not assigning a value ( "main" ) to
      the variable ( target ) ?
      What I want is to have the href statement to use a value 'passed' to the
      function in the "this.jumpU RL" line.

      We may have up to 6 different InLine Frames ( iFrames ) on our page, and
      each menu item passes the URL and target to the jumpURL function.
      The target can be any one of the 6 iFrames.

      I have hard coded the function for now as follows :

      this.jumpURL = function(url, target) {

      var targetF = "(Default)" // the default is the BodyFrame iFrame
      var targetS = "same" //target is same window
      var targetN = "_new" //target is a new window
      var NoURL = "(No URL)" //there is no URL for this menu button to link to
      var targetBF = "BodyFrame" // this is the name of 1 of the iFrames

      if(url == NoURL){
      targetF = "_";
      targetS = "_";
      targetN = "_";
      targetBF = "_";
      }

      if(target == targetF) if(url) BodyFrame.locat ion.href = url;
      if(target == targetBF) if(url) BodyFrame.locat ion.href = url;
      if(target == targetS) if(url) document.locati on.href = url;
      if(target == targetN) window.open(url );


      but would prefer to find a way to get it to work with the passes target
      value.

      Regards

      DaveO
      ---------------------------------------------------
      "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
      news:MPG.1cf678 0b3d3e22c798a5d 3@nntp.lucent.c om...
      In article <d6i6pk$ih2$1@c tb-nnrp2.saix.net> , jsinvest@mweb.c o.za
      enlightened
      us with...[color=blue]
      > this.jumpURL = function(url, target) {
      > if(url) target.location .href = url;
      >[/color]

      this.jumpURL = function(url, target) {
      if (url) {
      if (!target) {
      // call the default frame "main" or something
      target = "main";
      }
      top.frames[target].document.locat ion.href = url;
      }
      }

      And do note that while vb comparisons and assignments both use the "=" sign,
      javascript uses "=" for assignment and "==" for comparisons. A little tip
      for
      you. ;)

      --
      --
      ~kaeli~
      With her marriage, she got a new name and a dress.




      Comment

      • BootNic

        #4
        Re: set target frame for jumpURL function

        <script>
        function jump(url,Target ,I){
        // I == n for a Frame
        if (I == 'n'){
        top.frames[Target].location = "http://"+url
        }
        // I = y for an iframe
        if (I == 'y'){
        frames[Target].location.href = "http://"+url
        }
        // I is left blank for normal target
        if (I ==''){
        window.open("ht tp://"+url, Target,'');
        }
        }
        </script>


        <a href="javascrip t:jump('www.dow nload.com','fre e','n')">Frame</a><br>
        <a href="javascrip t:jump('www.www .sue.com','sue' ,'y')">Iframe</a><br>
        <a href="javascrip t:jump('www.gho st.com','spook' ,'')">Target</a><br>

        --
        BootNic Friday, May 20, 2005 12:23 PM

        The world is very different now. For man holds in his mortal hands the power to abolish all forms of
        human poverty, and all forms of human life.
        *John Fitzgerald Kennedy, Inaugural Address*
        [color=blue]
        > "DaveO" <jsinvest@mweb. co.za> wrote:
        > news:d6k1ao$l82 $1@ctb-nnrp2.saix.net. ...
        >
        > Hi kaeli
        >
        > Many thanks for the info.
        >
        > However, is the line target = "main" not assigning a value (
        > "main" ) to the variable ( target ) ?
        > What I want is to have the href statement to use a value 'passed' to
        > the function in the "this.jumpU RL" line.
        >
        > We may have up to 6 different InLine Frames ( iFrames ) on our page,
        > and each menu item passes the URL and target to the jumpURL function.
        > The target can be any one of the 6 iFrames.
        >
        > I have hard coded the function for now as follows :
        >
        > this.jumpURL = function(url, target) {
        >
        > var targetF = "(Default)" // the default is the BodyFrame iFrame
        > var targetS = "same" //target is same window
        > var targetN = "_new" //target is a new window
        > var NoURL = "(No URL)" //there is no URL for this menu button to
        > link to var targetBF = "BodyFrame" // this is the name of 1 of the
        > iFrames
        >
        > if(url == NoURL){
        > targetF = "_";
        > targetS = "_";
        > targetN = "_";
        > targetBF = "_";
        > }
        >
        > if(target == targetF) if(url) BodyFrame.locat ion.href = url;
        > if(target == targetBF) if(url) BodyFrame.locat ion.href = url;
        > if(target == targetS) if(url) document.locati on.href = url;
        > if(target == targetN) window.open(url );
        >
        >
        > but would prefer to find a way to get it to work with the passes
        > target value.
        >
        > Regards
        >
        > DaveO
        > ---------------------------------------------------
        > "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
        > news:MPG.1cf678 0b3d3e22c798a5d 3@nntp.lucent.c om...
        > In article <d6i6pk$ih2$1@c tb-nnrp2.saix.net> , jsinvest@mweb.c o.za
        > enlightened
        > us with...[color=green]
        >> this.jumpURL = function(url, target) {
        >> if(url) target.location .href = url;
        >>[/color]
        >
        > this.jumpURL = function(url, target) {
        > if (url) {
        > if (!target) {
        > // call the default frame "main" or something
        > target = "main";
        > }
        > top.frames[target].document.locat ion.href = url;
        > }
        > }
        >
        > And do note that while vb comparisons and assignments both use the
        > "=" sign, javascript uses "=" for assignment and "==" for
        > comparisons. A little tip for
        > you. ;)
        >
        > --[/color]

        Comment

        • DaveO

          #5
          Re: set target frame for jumpURL function

          Hi All

          Many Thanks for the solution.

          Your kindness is appreciated greatly.

          Regards

          DaveO

          ---------------------------------------------------
          "BootNic" <Bootnic@bounce .prodigy.net> wrote in message
          news:tboje.1477 $H24.1245@newss vr17.news.prodi gy.com...
          <script>
          function jump(url,Target ,I){
          // I == n for a Frame
          if (I == 'n'){
          top.frames[Target].location = "http://"+url
          }
          // I = y for an iframe
          if (I == 'y'){
          frames[Target].location.href = "http://"+url
          }
          // I is left blank for normal target
          if (I ==''){
          window.open("ht tp://"+url, Target,'');
          }
          }
          </script>


          <a href="javascrip t:jump('www.dow nload.com','fre e','n')">Frame</a><br>
          <a href="javascrip t:jump('www.www .sue.com','sue' ,'y')">Iframe</a><br>
          <a href="javascrip t:jump('www.gho st.com','spook' ,'')">Target</a><br>

          --
          BootNic Friday, May 20, 2005 12:23 PM

          The world is very different now. For man holds in his mortal hands the power
          to abolish all forms of
          human poverty, and all forms of human life.
          *John Fitzgerald Kennedy, Inaugural Address*
          [color=blue]
          > "DaveO" <jsinvest@mweb. co.za> wrote:
          > news:d6k1ao$l82 $1@ctb-nnrp2.saix.net. ...
          >
          > Hi kaeli
          >
          > Many thanks for the info.
          >
          > However, is the line target = "main" not assigning a value (
          > "main" ) to the variable ( target ) ?
          > What I want is to have the href statement to use a value 'passed' to
          > the function in the "this.jumpU RL" line.
          >
          > We may have up to 6 different InLine Frames ( iFrames ) on our page,
          > and each menu item passes the URL and target to the jumpURL function.
          > The target can be any one of the 6 iFrames.
          >
          > I have hard coded the function for now as follows :
          >
          > this.jumpURL = function(url, target) {
          >
          > var targetF = "(Default)" // the default is the BodyFrame iFrame
          > var targetS = "same" //target is same window
          > var targetN = "_new" //target is a new window
          > var NoURL = "(No URL)" //there is no URL for this menu button to
          > link to var targetBF = "BodyFrame" // this is the name of 1 of the
          > iFrames
          >
          > if(url == NoURL){
          > targetF = "_";
          > targetS = "_";
          > targetN = "_";
          > targetBF = "_";
          > }
          >
          > if(target == targetF) if(url) BodyFrame.locat ion.href = url;
          > if(target == targetBF) if(url) BodyFrame.locat ion.href = url;
          > if(target == targetS) if(url) document.locati on.href = url;
          > if(target == targetN) window.open(url );
          >
          >
          > but would prefer to find a way to get it to work with the passes
          > target value.
          >
          > Regards
          >
          > DaveO
          > ---------------------------------------------------
          > "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
          > news:MPG.1cf678 0b3d3e22c798a5d 3@nntp.lucent.c om...
          > In article <d6i6pk$ih2$1@c tb-nnrp2.saix.net> , jsinvest@mweb.c o.za
          > enlightened
          > us with...[color=green]
          >> this.jumpURL = function(url, target) {
          >> if(url) target.location .href = url;
          >>[/color]
          >
          > this.jumpURL = function(url, target) {
          > if (url) {
          > if (!target) {
          > // call the default frame "main" or something
          > target = "main";
          > }
          > top.frames[target].document.locat ion.href = url;
          > }
          > }
          >
          > And do note that while vb comparisons and assignments both use the
          > "=" sign, javascript uses "=" for assignment and "==" for
          > comparisons. A little tip for
          > you. ;)
          >
          > --[/color]


          Comment

          Working...