javascript - Can I give dynamic paths for images and css purely in client side? -


can give dynamic paths images , css through jquery/javascript/html or other technology available in client side? below dummy code:

<html>   my_constant_path = "/yes/i/got/this/"  <head>   <link rel="stylesheet" href="<my_constant_path>" + "style.css"/>   </head>  <body>  <div>    <img src= "<my_constant_path>" + "abc.png"/>   </div>  </body> </html> 

i cannot use server side script.

if going apply my_constant_path images/links

you use <base> element @ head section , change href attribute via javascript follows:

<head>   <meta charset="utf-8">   <title>title</title>   <base href="">   <script>     function setbaseurl(url) {        document.getelementsbytagname("base")[0].href = url;     }       setbaseurl("http://placehold.it/");   </script> </head> 

then enter href/src attributes of elements relatively:

<img src="200x150" alt=""> 

working demo.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -