Different CSS per specific url

1557
February 21, 2017, at 11:11 PM

I want to add specific css when url changes :

exemple : example.org/43-product.html#/2-size-s/11-color-black/28-modele-coffee

when i select attribute on my site , the url change like if i select the white color that will give me :

example.org/43-product.html#/2-size-s/8-color-white/28-modele-coffee

i want to put a background , when the color black is selected and an other for the white and for every possible combinations.

I used this function for checking the url

<script type="text/javascript">
$(document).ready(function () {
if(window.location.href.indexOf("franky") > -1) {
   alert("your url contains the name franky");
}
});
</script>

but work only if I refresh the page, is there a way to make it work so that the url changes without any refresh ? Thanks

Help me in this, Thanks

Answer 1

You can save your style.css as style.css.php and fill the top with e.g:

<?php
     header('Content-type: text/css');
     $background_color = htmlentities($_GET['background_color'], ENT_QUOTES, 'UTF-8');
?>
/* CSS code goes here */

...or something similar. Please note that the code is just provided as an example and not secure (Missing if color is set, color exists...)

READ ALSO
Why the javascript run again after postback in .net

Why the javascript run again after postback in .net

When page_load a Javascript runs from C# code behind using ScriptManagerRegisterStartupScript and it's in if(!IsPostBack) from page_load

188
Is there a way to get previous radio value in &ldquo;click&rdquo; or &ldquo;change&rdquo; event handler?

Is there a way to get previous radio value in “click” or “change” event handler?

I need to know if user clicked to already checked radio or he made a new choiceNow I detect it via "focus", "click" and "change" events combination (store old value in "focus", and compare it with current in "click" or "change" to detect and handle click to already...

173
How to use @Gbuomprisco/ng2-tag-input with angular-cli?

How to use @Gbuomprisco/ng2-tag-input with angular-cli?

I am using latest version of @angular/cli (10

263