ian ian - 5 months ago 10
PHP Question

Need base url inside javascript tags

I am trying to use the base url of my php page inside javascript tags but I don't know javascript very well. I use baseUrl;?> in PHP but that doesn't work in javascript. Can anyone tell me what I can use to replace baseUrl;?> below?

<script>
window.onload = function () {
BobbieEDITOR.replace("plados", {
contentsCss: "<?php echo $this->baseUrl;?>data/css/bltry.css"
});
};
</script>

Answer

Try this, use Referenced pages (below) to fine tune it:

<script>
    window.onload = function () {
        var baseUrl = window.location.host;
        BobbieEDITOR.replace("plados", baseUrl + '/data/css/bltry.css');
    };
</script>

References:

https://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/

Get current URL in web browser

http://tech-blog.maddyzone.com/javascript/get-current-url-javascript-jquery