473,394 Members | 1,737 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,394 software developers and data experts.

Javascript makes the current directory to change?

Hi,

I'm not sure if my question is really related to JavaScript, so please excuse me if that's not the case (and maybe you guys would have an idea what's the cause is and where could I ask)...

I recently put the following script online:
<script type="text/javascript"><!--
function playmedia(mediafile) {
newwindow=window.open();
if (window.focus) {newwindow.focus()}
newwindow.document.write('<html>');
newwindow.document.write(' <head>');
newwindow.document.write(' <title>Media player</title>');
newwindow.document.write(' </head>');
newwindow.document.write(' <body bgcolor="#A0A0FF" text="#000000">');
newwindow.document.write(' <center>');
newwindow.document.write(' <h2>Playing the media file... ♫</h2><br>');
newwindow.document.write(' <!-- show play button, autostart and loop once -->');
newwindow.document.write(' <embed src="' + mediafile + '" hidden=false autostart=true loop=1 autosize=1>');
newwindow.document.write(' </center>');
newwindow.document.write(' </body>');
newwindow.document.write('</html>');
newwindow.document.close();
}
//--></script>
I call this script using the following link:
<a href="errorJS.htm" onclick="playmedia('../goodies/antarcti/antarcti.mid'); return false;">Play</a>

So far, so good: the script is working, and I do not have any problem.
Troubles comes when I want to use my website locally (I often gave an offline copy to my relatives, as they prefer to use it offline). When used from the disk, the browser (Fx) can't find the file. If I change the link from playmedia('../goodies/antarcti/antarcti.mid') to playmedia('goodies/antarcti/antarcti.mid'), then it works offline, but when put on the server I get an 404 :(
I'm using frames, too. The main frame is in / , sub-frames are in /html/ , and the media files are stored in /goodies/. It seems that in some circumstances, the "current" directory isn't the same...

Now the big question comes: Is this some Javascript-related issue? If not, what could be the problem? The browser? My web server?

The website is at http://viste.homeip.net/mateusz/nes

Best regards,
Mateusz Viste
Sep 7 '08 #1
8 5181
SAM
Mateusz Viste a crit :
Hi,

I'm not sure if my question is really related to JavaScript, so please excuse me if that's not the case (and maybe you guys would have an idea what's the cause is and where could I ask)...
I thhink you have to learn about absolute and relative links ...
In relative you have 2 possibilities
- relative to the file : href="imag.jpg" href="../../folder/img.jpg"
- relative to root of site : href="/folder/images/img.jpg"

You seem to use relative link alternatively locally and on server,
But, apparently you want to use relative to the file (and not to the
root of site).

So the script must be in the correct folder on server and locally
that's to say in a folder on same floor than folder 'goodies'

[folder or site]
[nes]
[htm_roms]
file : popup.htm (with the script)
(or linked to the script at any place)
[goodies]
[antarcti]
file : antarcti.mid

or,
on server (site = http://viste.homeip.net/mateusz/) :
site/nes/htm_roms/popup.htm
site/nes/goodies/antarcti/antarcti.mid
on PC :
C:Documents/Mysite/nes/htm_roms/popup.htm
C:Documents/Mysite/nes/goodies/antarcti/antarcti.mid

If all that seems correct to you at home and on site,
look at precisely the names of your folders and files in both places.
It's possible that some of them has(have) their 1st letter in uppercase.
At home there is no importance, on site that's count (antarcti not same
as Antarcti) and href must reflects the correct spelling.

--
sm
Sep 7 '08 #2
В Воскресенье 07 сентября 2008 15:58, SAM писал:
I thhink you have to learn about absolute and relative links ...
In relative you have 2 possibilities
- relative to the file : href="imag.jpg" href="../../folder/img.jpg"
- relative to root of site : href="/folder/images/img.jpg"
Yes, I exactly know what you are talking about :-)
You seem to use relative link alternatively locally and on server,
But, apparently you want to use relative to the file (and not to the
root of site).
I am always using relative links. That allows me to use the website as an
online page, and to copy it easily to other computers without any problem.
So the script must be in the correct folder on server and locally
that's to say in a folder on same floor than folder 'goodies'
Agin, you are 100% right ;-)
If all that seems correct to you at home and on site,
look at precisely the names of your folders and files in both places.
Names are correct. By the way, both my web server and my PC are
case-sensitive (I am using Linux on both).

The problem is the following:
On my local PC, the script needs to be called like that:
playmedia('goodies/antarcti/antarcti.mid')

Just like it would be in the root directory (in fact, it is not, but at the
begin I assumed that JavaScript is acting like that).

When I put the same script/website on my web server, my browser (the same I
used locally - Firefox 3.0.1) is acting like the current directory wasn't
the same anymore:

GET /mateusz/nes/htm_roms/goodies/advisln3/advtitle.mid HTTP/1.1

Which is not correct, as the root of the website is /mateusz/nes , and the
media file is in /mateusz/nes/goodies/advisln3/advtitle.mid :(

And that is the point which I definetely doesn't understand - why my browser
is changing the reference path when used locally... I just don't really
know where I have to search - is it a Firefox bug, something
JavaScript-specific, anything else...? But I guess it's offtopic for this
group anyway :-)

Best regards,
Mateusz Viste
Sep 7 '08 #3
SAM
Mateusz Viste a écrit :
>
The problem is the following:
On my local PC, the script needs to be called like that:
playmedia('goodies/antarcti/antarcti.mid')

Just like it would be in the root directory (in fact, it is not, but at the
begin I assumed that JavaScript is acting like that).
Not at all !
That means folder 'goodies' is in same folder than the file that opens
the popup. (you certainly have a copy of 'goodies' or an alias of it in
'htm_roms' on your PC, or you did get one and Fx uses its cache)

the file with the script could be here : /nes/htm_roms/
when midi file is here : /nes/htm_roms/goodies/antarcti/

The JS follows relative links from the page where it is declared
(or linked), it could not happen any error about the hrefs it they are
set like in the page in html code.
When I put the same script/website on my web server, my browser (the same I
used locally - Firefox 3.0.1) is acting like the current directory wasn't
the same anymore:

GET /mateusz/nes/htm_roms/goodies/advisln3/advtitle.mid HTTP/1.1
That url is correct if the html file in 'htm_roms' calls :
'goodies/antarcti/antarcti.mid'
Which is not correct, as the root of the website is /mateusz/nes ,
more probably the exact root is : /mateusz/ (href="/")
/nes/ is a kind of sub-site (its relative root is : href="/nes/" )
and the
media file is in /mateusz/nes/goodies/advisln3/advtitle.mid :(
Right ! :-)
And that is the point which I definetely doesn't understand - why my browser
is changing the reference path when used locally...
No it doesn't, it can't !

delete your folder 'goodies' in 'htm_roms' on your PC
(or move it back to 'nes')
don't know where I have to search - is it a Firefox bug, something
JavaScript-specific, anything else...? But I guess it's offtopic for this
group anyway :-)
Well, I see here, in your page :
<http://viste.homeip.net/mateusz/nes/htm_roms/advisln3.htm>
with the code (correct as 'htm_roms' is with 'goodies' in 'nes'):

<a href="../goodies/advisln3/advtitle.mid" target="_blank">
Adventure Island 3 title music theme</a>

In the head of this page you could have :

<script type="text/javascript" src="../js/sound.js"></script>

Then you save in folder /nes/js/
the file 'sound.js' containing exactly :

function pop(what) {
if(typeof nw = 'undefined' || nw.closed)
nw = window.open('','','width=300,height=60,resizable=1 ');
nw.location = what.href; // to avoid any mistake
nw.focus();
return false;
}

Then your link becomes :

<a href="../goodies/advisln3/advtitle.mid" target="_blank"
onclick="return pop(this);" title="To listen the musical theme">
Adventure Island 3 title music theme</a>
=================
You can also have the script in your menu's page
<http://viste.homeip.net/mateusz/nes/html/index.htm>

<head>
<title>NES games repository</title>
<meta
(...)
<script type="text/javascript" src="../js/sound.js"></script>
</head>

The opened pages in right frame no more have JS's script
and their links to play sound are this way :

<a href="../goodies/advisln3/advtitle.mid" target="_blank"
onclick="return parent.index.pop(this);"
title="To listen the musical theme">
Adventure Island 3 title music theme</a>
=================
You can also have the script in your main page :
<http://viste.homeip.net/mateusz/nes/index.htm>

<script type="text/javascript" src="js/sound.js"></script>
</head>

Right pages will be without JS and with links this kind :

<a href="../goodies/advisln3/advtitle.mid" target="_blank"
onclick="return parent.pop(this);"
title="To listen the musical theme">
Adventure Island 3 title music theme</a>

--
sm
Sep 7 '08 #4
Hi :-)

В Воскресенье 07 сентября 2008 20:02, SAM писал:
That means folder 'goodies' is in same folder than the file that opens
the popup. (you certainly have a copy of 'goodies' or an alias of it in
'htm_roms' on your PC, or you did get one and Fx uses its cache)
No, there was never any "goodies" directory in "htm_roms"...
the file with the script could be here : /nes/htm_roms/
That's true. Well, in fact, that's the location of the script which
generates the <embedline to play multimedia stuff into a
newwindow.document.
The JS follows relative links from the page where it is declared
(or linked), it could not happen any error about the hrefs it they are
set like in the page in html code.
That what I believed in until today. :-)
>When I put the same script/website on my web server, my browser (the same
I used locally - Firefox 3.0.1) is acting like the current directory
wasn't the same anymore:

GET /mateusz/nes/htm_roms/goodies/advisln3/advtitle.mid HTTP/1.1

That url is correct if the html file in 'htm_roms' calls :
'goodies/antarcti/antarcti.mid'
No, there is no goodies in htm_roms. The essential question which is black
magic for me, is why Firefox tries to find the media
in /mateusz/nes/htm_roms/goodies/advisln3/advtitle.mid, but when runned
locally it finds it just fine in /mateusz/nes/goodies/advisln3/advtitle.mid
(I am talking about the first version of my script, which doesn't
added "..". The current version, which is online, do works fine remotely,
but doesn't locally).

Just try to save the page
http://viste.homeip.net/mateusz/nes/...s/advisln3.htm and the file
http://viste.homeip.net/mateusz/nes/...3/advtitle.mid to your
disk (locally - just pay attention to respect relative links), and try to
run it. It won't (at least for me it is not - I have to remove "../" to
make it work).
>Which is not correct, as the root of the website is /mateusz/nes ,

more probably the exact root is : /mateusz/ (href="/")
/nes/ is a kind of sub-site (its relative root is : href="/nes/" )
Yes, these are subdirectories. I tried to put it directly into /, but it
isn't changing anything.
delete your folder 'goodies' in 'htm_roms' on your PC
(or move it back to 'nes')
There never was such... :-D
The stuff which is online is an exact copy of what I have on disk.
That's the whole point: the same version of the code doesn't work locally
and remotely. It works locally OR remotely, depending on how I generate my
script.
Well, I see here, in your page :
<http://viste.homeip.net/mateusz/nes/htm_roms/advisln3.htm>
with the code (correct as 'htm_roms' is with 'goodies' in 'nes'):

<a href="../goodies/advisln3/advtitle.mid" target="_blank">
Adventure Island 3 title music theme</a>
True.
In the head of this page you could have :

<script type="text/javascript" src="../js/sound.js"></script>

Then you save in folder /nes/js/
the file 'sound.js' containing exactly :
That seems to be some very clever code. I will have to read it several times
tomorrow to understand what is it about :-)
Is it some routine which detects the current path of the program, allowing
to not bother about relative paths anymore?

Anyway, much thanks for your investigations :-)

Best regards,
Mateusz Viste
Sep 7 '08 #5
SAM
Mateusz Viste a écrit :
>
The current version, which is online, do works fine remotely,
but doesn't locally).

Just try to save the page
http://viste.homeip.net/mateusz/nes/...s/advisln3.htm and the file
http://viste.homeip.net/mateusz/nes/...3/advtitle.mid to your
disk (locally - just pay attention to respect relative links), and try to
run it. It won't (at least for me it is not - I have to remove "../" to
make it work).
I'm sorry, downloaded in correct folders your files as you can see :
<http://cjoint.com/?jhxsPergjb>
All run as expected (locally) when I click 'Play'
<file:///Users/stef/Documents/aaa/nes/htm/advisln3.htm>
except that I haven't the console (width and height are needed)
>delete your folder 'goodies' in 'htm_roms' on your PC
(or move it back to 'nes')

There never was such... :-D
The stuff which is online is an exact copy of what I have on disk.
I can't believe you, or your Linux is playing a jock to you.
(do you use the correct url to open the file locally ?)
(drag the file and drop it in the Firefox's window)

At least, did you try locally with another browser ?
That's the whole point: the same version of the code doesn't work locally
and remotely. It works locally OR remotely, depending on how I generate my
script.
Please try (locally and on site) this version of your html file
(donwload it at the right place !):
<http://cjoint.com/data/jhxECGhbPf_advisln3_asm.htm>
and click the link : 'Adventure Island 3 title music theme'
(there is another script with automatic src for the embed)

Don't try it on the site cjoint.com
>In the head of this page you could have :

<script type="text/javascript" src="../js/sound.js"></script>

Then you save in folder /nes/js/
the file 'sound.js' containing exactly :

That seems to be some very clever code. I will have to read it several times
tomorrow to understand what is it about :-)
It is about external JS file linked to each page needing this code.
The JS code will be put in browser's cache, downloaded only once for all
the pages
Is it some routine which detects the current path of the program, allowing
to not bother about relative paths anymore?
It use the href of the link to give it to embed's src.
If the link works when JS is disabled, the popup must (and has to) work
too if JS is enabled.
Anyway, much thanks for your investigations :-)
You can say it ! :-)

--
sm
Sep 7 '08 #6
В Воскресенье 07 сентября 2008 23:52, SAM писал:
I'm sorry, downloaded in correct folders your files as you can see :
<http://cjoint.com/?jhxsPergjb>
All run as expected (locally) when I click 'Play'
Yes, I know :)
I have done the same, and that works. Therefore I localized what exactly
make it to not work - frames. When I download the following files:
http://viste.homeip.net/mateusz/nes/index.htm
http://viste.homeip.net/mateusz/nes/html/index.htm
http://viste.homeip.net/mateusz/nes/...s/advisln3.htm
http://viste.homeip.net/mateusz/nes/...3/advtitle.mid

and launch the main, big (containing 2 frames) index.htm, then it doesn't
work locally.
When run locally, Firefox takes the href of the main "frame container", when
run remotely, it takes the href of the child frame.
I can't believe you, or your Linux is playing a jock to you.
I know it looks bad :-P
Now, I am 99% sure that the "joke" comes from Firefox 3. I tried today at
work, on a Windows machine, and when used locally, it was almost working. I
wrote "almost", because the MS media player told "root could have been
changed" and don't wanted to play the file, but it was able to find it at
all. That made me curious, so I downgraded my Firefox at home from v3.0.1
to v2, and IT WORKS. So my sentence is: Firefox 3 sux :-D
(do you use the correct url to open the file locally ?)
(drag the file and drop it in the Firefox's window)
Please trust me - I'm not *that* dumb. ;-) In fact, I work as a network
engineer, I'm just crap when it comes to JavaScript stuff :-)
At least, did you try locally with another browser ?
As I wrote, I tried today at work. I can't really test with another browser
on my own machine, as I does not have any multimedia plugins for Opera nor
Konqueror (Firefox is the only one which is able to play <embedfiles).
Anyway, it doesn't matter anymore.
Please try (locally and on site) this version of your html file
(donwload it at the right place !):
<http://cjoint.com/data/jhxECGhbPf_advisln3_asm.htm>
and click the link : 'Adventure Island 3 title music theme'
(there is another script with automatic src for the embed)
I downloaded it (using wget, to be sure that it won't be modified on the
fly), I replaced my previous advisln3.htm file, and it doesn't work either.

I think that discussion may be ended here.

I am really grateful for the great help you had the kindness to provide to
me. Many thanks for your friendly advices, it made be find the faulty part
of the puzzle much quicker than if I had to troubleshoot it by myself (in
fact, I was 75% sure that the problem was in the JavaScript code, so I
would have a very very long way to go) :-)

Best regards,
Mateusz Viste
Sep 8 '08 #7
SAM
Mateusz Viste a écrit :
В Воскресенье 07 сентября 2008 23:52, SAM писал:
Therefore I localized what exactly
make it to not work - frames. When I download the following files:
http://viste.homeip.net/mateusz/nes/index.htm
http://viste.homeip.net/mateusz/nes/html/index.htm
http://viste.homeip.net/mateusz/nes/...s/advisln3.htm
http://viste.homeip.net/mateusz/nes/...3/advtitle.mid

and launch the main, big (containing 2 frames) index.htm, then it doesn't
work locally.
When run locally, Firefox takes the href of the main "frame container",
Tremendous ! that's true :-(
so I downgraded my Firefox at home from v3.0.1
to v2, and IT WORKS. So my sentence is: Firefox 3 sux :-D
;-(
As I wrote, I tried today at work. I can't really test with another browser
on my own machine, as I does not have any multimedia plugins for Opera nor
Konqueror (Firefox is the only one which is able to play <embedfiles).
Anyway, it doesn't matter anymore.
And IE ?
<http://www.tatanka.com.br/ies4linux/>
(don't play midi files on my ies4osx (Mac) but Flash seems OK)

>Please try (locally and on site) this version of your html file
<http://cjoint.com/data/jhxECGhbPf_advisln3_asm.htm>
and click the link : 'Adventure Island 3 title music theme'

I downloaded it (using wget, to be sure that it won't be modified on the
fly), I replaced my previous advisln3.htm file, and it doesn't work either.
It does locally in framed page with Fx.3.
I mean : the left link (Adventure Island 3 title music theme)
I think that discussion may be ended here.
Yeap !

SYL
--
sm
Sep 8 '08 #8
Just for future generations, here is a version of the script which works both remotely and locally on Firefox. The solution has been kindly given to me by SAM ;-)

First, we have to declare the script in the <headsection of the page:

<script type="text/javascript"><!--
function playmedia(mediafile) {
newwindow=window.open();
if (window.focus) {newwindow.focus()}
newwindow.document.write('<html>');
newwindow.document.write(' <head>');
newwindow.document.write(' <title>Media player</title>');
newwindow.document.write(' </head>');
newwindow.document.write(' <body bgcolor="#A0A0FF" text="#000000">');
newwindow.document.write(' <center>');
newwindow.document.write(' <h2>Playing the media file... ♫</h2><br>');
newwindow.document.write(' <!-- show play button, autostart and loop once -->');
newwindow.document.write(' <embed src="' + mediafile + '" hidden=false autostart=true loop=1 autosize=1>');
newwindow.document.write(' </center>');
newwindow.document.write(' </body>');
newwindow.document.write('</html>');
newwindow.document.close();
}
//--></script>

Then, we call it using the following link:

<a href="../goodies/chipdale/speedrun.flv" onclick="playmedia(this.href); return false;">Play</a>

Mateusz Viste
Sep 9 '08 #9

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

Similar topics

53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
3
by: M Wells | last post by:
Hi All, Just wondering how you go about changing the value of a session cookie via javascript? I have a PHP page that sets a session cookie when it first loads. I'd like to be able to change...
7
by: Bert | last post by:
I have been reading the post and the FAQ and have been unable to find anything that will help with my problem. First let me say that I am not a web developer, designer and no next to nothing...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.