window.open - url variable ?

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

    window.open - url variable ?

    Really can't figure this out, would appreciate some help...

    Have a textbox in a form which user types in a url link.

    When they click a button I'd like it to open a new window,
    and attempt to display the link they've typed in the textbox.

    I've got the button calling a javascript with onclick,
    but I can't get the window that opens to accept the dynamic url.

    The textbox name is txtlink.

    var thelink = txtlink.value;
    testlinkwindow = window.open();

    Is there a way to get the variable as the url parameter of open() ?

    The other thing I've tried is setting the location.href of the child window,
    but that doesn't work either. :-(

    eg
    testlinkwindow = window.open();
    testlinkwindow. location.href= txtlink.value;

    Please can you help ?
    R.


  • Randy Webb

    #2
    Re: window.open - url variable ?

    R45six wrote:[color=blue]
    > Really can't figure this out, would appreciate some help...
    >
    > Have a textbox in a form which user types in a url link.
    >
    > When they click a button I'd like it to open a new window,
    > and attempt to display the link they've typed in the textbox.
    >
    > I've got the button calling a javascript with onclick,
    > but I can't get the window that opens to accept the dynamic url.
    >
    > The textbox name is txtlink.
    >
    > var thelink = txtlink.value;
    > testlinkwindow = window.open();[/color]


    var thelink = document.forms['formname'].elements['txtlink'].value
    window.open (thelink)



    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • GreenLight

      #3
      Re: window.open - url variable ?

      "R45six" <news.richardNO @SPAMntlworld.c om> wrote in message news:<LOEoc.149 2$351.1322@news fe6-gui.server.ntli .net>...[color=blue]
      > Really can't figure this out, would appreciate some help...
      >
      > Have a textbox in a form which user types in a url link.
      >
      > When they click a button I'd like it to open a new window,
      > and attempt to display the link they've typed in the textbox.
      >
      > I've got the button calling a javascript with onclick,
      > but I can't get the window that opens to accept the dynamic url.
      >
      > The textbox name is txtlink.
      >
      > var thelink = txtlink.value;
      > testlinkwindow = window.open();
      >
      > Is there a way to get the variable as the url parameter of open() ?[/color]

      Have you tried actually passing it as the URL parameter? You don't
      have any parameters to open() in the posted code.

      Have a look here:

      The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.

      Comment

      • R45six

        #4
        Re: window.open - url variable ?

        > var thelink = document.forms['formname'].elements['txtlink'].value[color=blue]
        > window.open (thelink)[/color]

        Cheers, couldn't get it accept a variable inside the brackets.

        I think it was also a problem, not naming the form.

        Ended up with this.

        var thelink = formname.txtlin k.value
        window.open("" + thelink)


        Comment

        • Randy Webb

          #5
          Re: window.open - url variable ?

          R45six wrote:[color=blue][color=green]
          >>var thelink = document.forms['formname'].elements['txtlink'].value
          >>window.open (thelink)[/color]
          >
          >
          > Cheers, couldn't get it accept a variable inside the brackets.
          >
          > I think it was also a problem, not naming the form.
          >
          > Ended up with this.
          >
          > var thelink = formname.txtlin k.value
          > window.open("" + thelink)[/color]


          var myVar = "txtlink";
          document.forms['formName'].elements[myVar].value;

          you have to drop the quotes inside the brackets when using a variable.

          --
          Randy
          Chance Favors The Prepared Mind
          comp.lang.javas cript FAQ - http://jibbering.com/faq/

          Comment

          Working...