Home › Forums › JavaScript › [Java Script Help] URL to Root
- This topic is empty.
-
AuthorPosts
-
March 13, 2013 at 9:02 pm #43375pedramMember
Hi there,
i’m not similar with js,
i want to set url to root (of course without write domain name)
is there a way?look at my e.g:
AudioPlayer.embed(“audioplayer_1”, {soundFile: “https://css-tricks.com/Player/player.mp3”});
i want to set address to root folder instead url (domain name)
something like this:
AudioPlayer.embed(“audioplayer_1”, {soundFile: “~/Player/player.mp3”});
March 13, 2013 at 9:10 pm #128127CrocoDillonParticipantAudioPlayer.embed(“audioplayer_1”, {soundFile: “/Player/player.mp3”});
doesn’t work? I don’t know about the AudioPlayer but normally starting an url with / means it’s relative to root.
March 14, 2013 at 6:23 am #128132pedramMemberit does, but the problem is audio player normally works with DOMAIN URL, not path address. but i’m working on a MOD for audio player, need to use a global script (or url) to root, look at the path of this mod:
Root/Player/Song.mp3
Root/Themes/Default/Scipts/Player.js
so that embed script placed into player.js , and i can’t write a certain url, cause i don’t know the all people url :) , with php we write something like this:
global $siteurl; echo ‘
src=”‘$siteurl’/player/Song.mp3but i need to do this via java script, cause audio player based on JS.
so, i need a global call script to root, or domain name, for eveyone, not only myselft, that mean, when using of this MOD, it load songs from Root, and of course i can’t tell the people, edit it manually your self.March 14, 2013 at 9:05 am #128180CrocoDillonParticipantI didn’t use ‘Root’ in my example. You might wanna try this [`window.location.hostname`](https://developer.mozilla.org/en-US/docs/DOM/window.location) but I’m not sure about browser compatibility.
March 15, 2013 at 5:57 am #128287pedramMemberImportant is how it should placed in link, is it correct?
AudioPlayer.embed(“audioplayer_1”, {soundFile: “window.location.hostname/Player/player.mp3”});
or must placed between ” or “” , i don’t know
anyway, it’s not workingMarch 15, 2013 at 7:45 am #128322CrocoDillonParticipantIf that’s in JavaScript its more like `{soundFile: window.location.hostname + “/Player/player.mp3”}` or something. Can you make a codepen?
March 15, 2013 at 1:02 pm #128373pedramMemberSure, here:
http://codepen.io/Pedram/pen/rslKGMarch 15, 2013 at 3:44 pm #128397GarrettParticipantYou can get the root location very easily, however because IE is a pain in the neck you’ll need to check both _location.hostname_ and _location.host_. Here is a function that will take care of that for you.
function getLocation() {
var hostname = document.location.hostname,
host = document.location.host;
return hostname == ” ? host == ” ? ” : host : hostname;
}To use this you would do the following.
AudioPlayer.embed(“audioplayer_1”, {
soundFile: getLocation() + “/Player/player.mp3”
});Hope this helped.
March 15, 2013 at 4:58 pm #128413pedramMemberThanks for reply, but not working neither,
it’s weird, when i add this code, player disappeared.
try it on my code pen :( -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.