Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

location.href can't find the location... 1

Status
Not open for further replies.

UncleMortis

Programmer
Jan 28, 2003
120
0
0
AU
I'm wondering what I'm doing wrong with the location.href . I can get it to take me to another page that's in the same folder as the page with the location.href. but when I ask it to find something in another folder, it won't find it. I've tried the same path in a normal html link and it finds it right away. Am I just missing something and a location.href will not find anything that's not in the same folder?

Code:
<html>
<body>
<span onMouseDown=&quot;window.status='Mouse Is Down'&quot;; onMouseUp=&quot;window.status='Mouse Is Up'&quot;; onDblClick=&quot;location.href='C:\My Documents\JavaScriptGoodies\thanksalot.html'&quot;;>
Click On this Text</span>
</body>
</html>
 
Ok, that didn't work either so I went back to the location.href and now the link tries to open the page that I've already got open and says it can't find it! I've changed it back to location.href and it still tried to open itself instead of the location listed above. It's really annoying me now. I don't understand why I'm telling it to go to a particular path it tries to open itself?

It's trying to find this page location C:\WINDOWS\Desktop\javatest\chp2_lesson8.html which is the address of the page that I'm clicking the link in. what's going on with that? It's the first time I've ever come across anything that is basically ignoring the path I'm asking for and giving me another path instead.
 
You could try and replace this part of your code:

onDblClick=&quot;location.href='C:\My Documents\JavaScriptGoodies\thanksalot.html'&quot;;>

with this:

onDblClick=&quot;location.href='file:///C:/My%20Documents/JavaScriptGoodies/thanksalot.html'&quot;;>


Best of Luck..

Brian
 
Why did it work Brian? And why didn't it work from the code that I already had. The way I've done it is the example from the book, other than me linking to the thanks page in another folder. What's with the %20 is that code to fill in the space between my documents? And should I have changed the slashes to face the other direction? Thanks for the help too.
 
Please understand that I am relatively new to JavaScript and if I give an explanation that is misleading I would hope that somebody would correct it for us.

The file was in a completely different folder is key here.

The &quot;\&quot; is the escape character in JavaScript.

for example, if you wanted to display double quotes inside of a string that is already inside of double quotes you would have to use the escape character. The &quot;\&quot; is ignored so the character that follows will be displayed

&quot;Hello &quot;JavaScript&quot;&quot; // This code would NOT work
'Hello &quot;JavaScript'&quot; // Hello &quot;JavaScript&quot;
&quot;Hello \&quot;JavaScript\&quot;&quot; // Hello &quot;JavaScript&quot;


The &quot;%20&quot; is the code that represents the space between words. A computer only will see numbers. Everything you type in is changed into a number so that your computer can read and process it. It is displayed back to you in a different format so that you can read it. The number &quot;20&quot; is the hexadecimal character code for a space.


C:+---My Documents+--MyWeb+
| | |
| | +--here.html
| | |
| | +--page1.html
| |
| +--JavaScriptGoodies+
| |
| +--thanksalot.html
+--New Folder+
|
+--New Page.html

To go from C:\My Documents\MyWeb\here.html to
C:\My Documents\MyWeb\page1.html

href=&quot;Page1.html&quot; (in the same folder)

To go from C:\My Documents\MyWeb\here.html to
C:\My Documents\JavaScriptGoodies\thanksalot.html

href=&quot;../JavaScriptGoodies/thanksalot.html&quot;

../ takes it back one folder level (My Documents)
JavaScriptGoodies/thanksalot.html path from My Documents

To go from C:\My Documents\MyWeb\here.html to
C:\New Folder\New Page.html

href=&quot;../../New%20Folder/New%20Page.html&quot;

../../ takes it back 2 folder levels (My Documents, C:)
New%20Folder/New%20Page.html path from C:

I am not sure of the path to the page you were at when you started so I gave you the full path. I bet it would work if you just simply put this in:

onDblClick=&quot;location.href='../JavaScriptGoodies/thanksalot.html'&quot;;>

add another ../ for each folder level you have to go back to get to the intended path.


Brian
 
Thank you very much for that explaination. I think the book I'm reading is more along the lines of &quot;have a look at what I've done&quot; whereas I'm actually typing the code so I get a handle on what's going on better and everynow and again I'm venturing into new territory as I try different things. Once again, thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top