How to use a CSS by the url of the site?

-4

I would like to know if I have a different CSS for a "Java" web system without having to include it in the source code?

I have a new CSS file that I resized the buttons and spaces and need to use it in this web application, I need to point the system to this new CSS without having to tinker with the source code.

A friend told me that I have to pass this through the URL, but I do not know how to do it ...

Example given by it link

Remembering that the system already has its CSS in the code.

Does anyone know how to do this?

    
asked by anonymous 25.06.2015 / 14:18

2 answers

5

Response

Impossible to do this.

Why?

Parameters in the URL are sent to the server, where is your source code, so in your code you will decide what to do with the parameter.

If you can not tinker with the source code, then you're talking about what CSS is, but the code is not "not there" because it does not know what to do with that information.

So you need some programming that imports this CSS file into your code, this is usually done on the server side, for example:

//Endereço: http://endereco_do_meu_sistema/?css=meucss.css

$css = empty($_GET['css']) ? null : $_GET['css'];
// "Importa" o arquivo meucss.css
if (!is_null($css))
   echo "<link href=\"$css\" rel=\"stylesheet\" type=\"text/css\">";

The previous example was written in PHP.

Alternative

Alternatively, you can import the file via Javascript, for example:

(function(css){
    var el = document.createElement('link');
    el.setAttribute('href', css);
    el.setAttribute('rel', 'stylesheet');
    el.setAttribute('type', 'text/css');
    document.body.appendChild(el);
})('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css')

For the modification to take place you must run this function every time you access the site (since you do not have access to the code, you can do this through the browser console if available) page reload the code should be run again, as these modifications are only made on the client side and are not saved on the server side.

Attention: This answer is for educational purposes only. NO example here should be used in production.

    
25.06.2015 / 15:50
0

To import a CSS file into a page, simply link to the HEAD block of the page you want to use, for example:

<link href="CAMINHO_DO_ARQUIVO_CSS.css" rel="stylesheet" />

However, of course, this css file must be within the directory of your site or on some public link that you have access to.

    
25.06.2015 / 14:29