Opening new window with datafile

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

    Opening new window with datafile

    All,

    I am completely new to Javascript but I have read some articles and
    examples
    about opening new windows from a webpage.

    However I am trying to open a data file ( in html format) that is not
    in the server dircetories but somewhere on my unix box.

    What I have sofar is:
    the script:
    function newwindow(url)
    {
    window.open(url ,'jav','width=4 00,height=600,s crollbars=yes;r esizable=yes');
    }


    the link :

    <a href="new.html" onClick="newwin dow('file:///tmp/x.html')\">Open
    here</a>

    .....and nothing happens. If i change the link to
    <a href="new.html" onClick="newwin dow('/tmp/x.html')\">Open here</a>

    .... I get a popup with the warning that the requested URL was not
    found on this server.

    How can I get a file to display in the popup without putting it on the
    server.

    Thanks in advance

    Regards

    KArel Bokhorst
  • Paul R

    #2
    Re: Opening new window with datafile

    Karel wrote:[color=blue]
    > All,
    >
    > I am completely new to Javascript but I have read some articles and
    > examples
    > about opening new windows from a webpage.
    >
    > However I am trying to open a data file ( in html format) that is not
    > in the server dircetories but somewhere on my unix box.
    >
    > What I have sofar is:
    > the script:
    > function newwindow(url)
    > {[/color]
    you have a rogue semicolon in here:[color=blue]
    > window.open(url ,'jav','width=4 00,height=600,s crollbars=yes;r esizable=yes');
    > }[/color]
    this function should return false to prevent the default click action
    taking place[color=blue]
    >
    >
    > the link :
    >
    > <a href="new.html" onClick="newwin dow('file:///tmp/x.html')\">Open
    > here</a>[/color]
    if you're sure you'll never want to see new.html, then replace with
    <a href="javascrip t:void(0)" onclick="... to be certain[color=blue]
    >
    > ....and nothing happens. If i change the link to
    > <a href="new.html" onClick="newwin dow('/tmp/x.html')\">Open here</a>
    >
    > ... I get a popup with the warning that the requested URL was not
    > found on this server.
    >
    > How can I get a file to display in the popup without putting it on the
    > server.[/color]

    If your page is hosted on a server, then attempting to access your local
    hard drive is likely to result in disappointment. Assuming both the
    original page and the page you want to open are hosted on your machine,
    then point your browser to the page you want to open and copy the
    address from there into your script.

    Comment

    • Randy Webb

      #3
      Re: Opening new window with datafile

      Paul R wrote:
      [color=blue]
      > Karel wrote:
      >[/color]

      <--snip-->
      [color=blue][color=green]
      >>
      >> <a href="new.html" onClick="newwin dow('file:///tmp/x.html')\">Open
      >> here</a>[/color]
      >
      > if you're sure you'll never want to see new.html, then replace with
      > <a href="javascrip t:void(0)" onclick="... to be certain[/color]

      NO! Even if the OP has limited use, please do not teach/propogate the
      bad habit of mis-using the javascript: pseudo-protocol.

      <a href="somePage. html" target="someWin dow"
      onclick="openWi ndow(this.href, this.target)">O pen Here</a>

      function openWindow(dest ination,windowN ame){
      window.open(des tination,window Name,'.....');
      }

      It is such a common problem that it is addressed in the group FAQ which
      was posted today to the group:



      --
      Randy
      comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

      Comment

      • Paul R

        #4
        Re: Opening new window with datafile

        Fair point. Indeed, for public websites, I'd recommend something simpler:

        <a href="mynewfile .htm" target="_blank" >...

        leaving the user in control of the window size, toolbars, etc. and
        giving no problems if scripting is switched off.

        That said, if you're going to use A onclick, beware bug #239295 in
        Firefox, which means the browser follows the link regardless of the
        onclick return value. (https://bugzilla.mozilla.org/show_bug.cgi?id=239295)

        Comment

        • Karel

          #5
          Re: Opening new window with datafile

          I solved this issue by using a cgi script.
          <a href="my.cgi?fi le=x.html"
          onClick="window .open('blank1', 'Error','width= 390,height=450, scrollbars=yes' )">

          The cgi script then deals with printing the contents of x.html to the
          popup.
          Maybe not the most elegant way, but it works for me.

          Thanks for the help.
          BTW: Excellent FAQ.

          Comment

          • Lee

            #6
            Re: Opening new window with datafile

            Paul R said:[color=blue]
            >
            >Fair point. Indeed, for public websites, I'd recommend something simpler:
            >
            ><a href="mynewfile .htm" target="_blank" >...
            >
            >leaving the user in control of the window size, toolbars, etc. and
            >giving no problems if scripting is switched off.
            >
            >That said, if you're going to use A onclick, beware bug #239295 in
            >Firefox, which means the browser follows the link regardless of the
            >onclick return value. (https://bugzilla.mozilla.org/show_bug.cgi?id=239295)[/color]

            That bug report has nothing to do with links and is complete nonsense, to boot.

            The following link is never followed in Firefox:

            <html>
            <body>
            <a href="http://www.google.com" onclick="return false">Demo</a>
            </body>
            </html>

            Comment

            • Paul R

              #7
              Re: Opening new window with datafile

              Lee wrote:
              ....[color=blue]
              > That bug report has nothing to do with links and is complete nonsense, to boot.
              >
              > The following link is never followed in Firefox:
              >
              > <html>
              > <body>
              > <a href="http://www.google.com" onclick="return false">Demo</a>
              > </body>
              > </html>
              >[/color]

              You're right and my favourite browser is blameless.

              My mistake was returning zero from onclick, instead of false. The effect
              turns out to be completely different:

              <html><head><ti tle>test page</title></head>
              <body>
              <p><a href='blank.htm ' onclick="return 0">goes somewhere</a></p>
              <p><a href='blank.htm ' onclick="return Boolean(0)">goe s nowhere</a></p>
              <p><a href='blank.htm ' onclick="return false">goes nowhere</a></p>
              </body>
              </html>

              An instance where data type seriously matters in JavaScript.

              Comment

              • Randy Webb

                #8
                Re: Opening new window with datafile

                Paul R wrote:
                [color=blue]
                > Fair point. Indeed, for public websites, I'd recommend something simpler:
                >
                > <a href="mynewfile .htm" target="_blank" >...
                >
                > leaving the user in control of the window size, toolbars, etc. and
                > giving no problems if scripting is switched off.[/color]

                That is worse as it does not reuse windows. That is why I used a unique
                name for the target and then referenced this.target as the window name
                of the window.open call.

                As far as "scripting is switched off", you should test what I posted
                before saying that.

                Put my code in a page along with your code. Click my link 100 times,
                tell me how many windows you have open. Repeat with your code.

                And, read the group FAQ with regards to quoting (among other things).

                --
                Randy
                comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

                Comment

                • Randy Webb

                  #9
                  Re: Opening new window with datafile

                  Karel wrote:
                  [color=blue]
                  > I solved this issue by using a cgi script.
                  > <a href="my.cgi?fi le=x.html"
                  > onClick="window .open('blank1', 'Error','width= 390,height=450, scrollbars=yes' )">
                  >
                  > The cgi script then deals with printing the contents of x.html to the
                  > popup.
                  > Maybe not the most elegant way, but it works for me.[/color]

                  "works for me" doesn't mean it will work for most people though.
                  [color=blue]
                  > Thanks for the help.
                  > BTW: Excellent FAQ.[/color]

                  You missed part of it. It deals with quoting what you are replying to.

                  --
                  Randy
                  comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

                  Comment

                  • Paul R

                    #10
                    Re: Opening new window with datafile

                    Randy Webb wrote:[color=blue]
                    > Paul R wrote:
                    >[color=green]
                    >> Fair point. Indeed, for public websites, I'd recommend something simpler:
                    >>
                    >> <a href="mynewfile .htm" target="_blank" >...
                    >>
                    >> leaving the user in control of the window size, toolbars, etc. and
                    >> giving no problems if scripting is switched off.[/color]
                    >
                    >
                    > That is worse as it does not reuse windows. That is why I used a unique
                    > name for the target and then referenced this.target as the window name
                    > of the window.open call.
                    >
                    > As far as "scripting is switched off", you should test what I posted
                    > before saying that.[/color]

                    Sorry, I wasn't very clear. What I wanted to say was that if one's aim
                    is simply to open a page in a new window, then HTML is usually
                    preferable to script; that web sites shouldn't use custom windows where
                    a hyperlink will suffice.

                    I agree that where script is appropriate, your example is the one to go
                    for, as it neatly handles both script-enabled and disabled browsers.

                    <...>
                    [color=blue]
                    >
                    > And, read the group FAQ with regards to quoting (among other things).
                    >[/color]
                    Have done, believe it or not. I'm a bit rusty on chapter 3 of
                    http://www.ietf.org/rfc/rfc1855.txt, however. I promise to beat myself
                    with birch twigs until I get it :-)

                    Comment

                    Working...