Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

~/ equivalent in javascript

Any smart way of doing a "root" based path referencing in JavaScript, just the way we have ~/ in ASP.NET?

like image 609
Vikram Avatar asked May 21 '09 14:05

Vikram


People also ask

What does`` mean in JavaScript?

The in operator returns true if the specified property is in the specified object or its prototype chain.

What is the pass equivalent in JavaScript?

Python's pass mainly exists because in Python whitespace matters within a block. In Javascript, the equivalent would be putting nothing within the block, i.e. {} . Show activity on this post. This is equivalent to leaving the block with nothing in it, but is good for readability reasons.


2 Answers

Have your page generate a tag with something like:

<link rel="home" id="ApplicationRoot" href="http://www.example.com/appRoot/" /> 

Then, have a function in JavaScript that extracts the value such as:

function getHome(){     return document.getElementById("ApplicationRoot").href; } 
like image 140
MiffTheFox Avatar answered Oct 13 '22 13:10

MiffTheFox


Use base tag:

<head>    <base href="http://www.example.com/myapp/" /> </head> 

...

from now any link use on this page, no matter in javascript or html, will be relative to the base tag, which is "http://www.example.com/myapp/".

like image 45
Kamarey Avatar answered Oct 13 '22 13:10

Kamarey