473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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=400,height=600,scroll bars=yes;resizable=yes');
}
the link :

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

.....and nothing happens. If i change the link to
<a href="new.html" onClick="newwindow('/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
Jul 23 '05 #1
9 1531
Karel wrote:
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)
{ you have a rogue semicolon in here: window.open(url,'jav','width=400,height=600,scroll bars=yes;resizable=yes');
} this function should return false to prevent the default click action
taking place

the link :

<a href="new.html" onClick="newwindow('file:///tmp/x.html')\">Open
here</a> if you're sure you'll never want to see new.html, then replace with
<a href="javascript:void(0)" onclick="... to be certain
....and nothing happens. If i change the link to
<a href="new.html" onClick="newwindow('/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.


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.
Jul 23 '05 #2
Paul R wrote:
Karel wrote:


<--snip-->

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


if you're sure you'll never want to see new.html, then replace with
<a href="javascript:void(0)" onclick="... to be certain


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="someWindow"
onclick="openWindow(this.href,this.target)">Open Here</a>

function openWindow(destination,windowName){
window.open(destination,windowName,'.....');
}

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

http://jibbering.com/faq/#FAQ4_24

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #3
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)
Jul 23 '05 #4
I solved this issue by using a cgi script.
<a href="my.cgi?file=x.html"
onClick="window.open('blank1','Error','width=390,h eight=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.
Jul 23 '05 #5
Lee
Paul R said:

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)


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>

Jul 23 '05 #6
Lee wrote:
....
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>


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><title>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)">goes 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.
Jul 23 '05 #7
Paul R wrote:
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 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.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #8
Karel wrote:
I solved this issue by using a cgi script.
<a href="my.cgi?file=x.html"
onClick="window.open('blank1','Error','width=390,h eight=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.
"works for me" doesn't mean it will work for most people though.
Thanks for the help.
BTW: Excellent FAQ.


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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #9
Randy Webb wrote:
Paul R wrote:
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 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.


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.

<...>

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

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 :-)
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dena Leiter | last post by:
I want to send people to a new page using a redirect but I want a new window to open. Is this possible? I've tried this: <meta http-equiv="refresh"...
44
by: Carlos Andr?s | last post by:
Hi everybody. I've got a problem. I'd like to avoid opening a new window when you have pressed the shift key and you click in the left button of the mouse. I've tried the next solution, in the...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
2
by: Keshav Gadia | last post by:
Hi, I am an ASP.net newbie. I am writing a user control that is made up of datagrid with one of the columns opening a new window to display some details on click of the set image. I have...
2
by: Zulander | last post by:
hi, i am trying to put a session variable in the DataFile of the XmlDataSource, but for some reason i am getting: Server tags cannot contain <% ... %constructs. <asp:XmlDataSource...
5
by: reubmeg | last post by:
I have a client who is having problems opening up queries in design mode. When the datafile that the query is looking at is in use by someone else, it takes up to a couple of minutes to open. I am...
1
by: sandy21380 | last post by:
Hello, Is there a way of opening an Access form without opening the Access window? Right now when I open the form, the Access window is a lot bigger than the form so I have to resize the Access...
3
by: nitriles | last post by:
Hello, i have a program in which i plot 10 subplots with matplotlib. To launch the program i now type in the console: python dataplot.py DATAFILE_10.10.07.csv However what i want is that python...
0
by: bbrewder | last post by:
I am struggling with some MSAccess automation issues. Basically, we have a .Net application that uses MSAccess for reporting (legacy code). We are able to launch MSAccess fine and even work with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.