Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Java Script Help] URL to Root

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #43375
    pedram
    Member

    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”});

    #128127
    CrocoDillon
    Participant

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

    #128132
    pedram
    Member

    it 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.mp3

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

    #128180
    CrocoDillon
    Participant

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

    #128287
    pedram
    Member

    Important 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 working

    #128322
    CrocoDillon
    Participant

    If that’s in JavaScript its more like `{soundFile: window.location.hostname + “/Player/player.mp3”}` or something. Can you make a codepen?

    #128373
    pedram
    Member
    #128397
    Garrett
    Participant

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

    #128413
    pedram
    Member

    Thanks for reply, but not working neither,
    it’s weird, when i add this code, player disappeared.
    try it on my code pen :(

    http://codepen.io/Pedram/pen/rslKG

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.