Opening new window with datafile

K

Karel

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,scrollbars=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
 
R

Randy Webb

Paul said:
Karel wrote:



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
 
L

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>
 
K

Karel

I solved this issue by using a cgi script.
<a href="my.cgi?file=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.
 
R

Randy Webb

Paul 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 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).
 
R

Randy Webb

Karel said:
I solved this issue by using a cgi script.
<a href="my.cgi?file=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.

"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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top