我想在 url
更改时添加特定的 css
:
例子:
example.org/43-product.html#/2-size-s/11-color-black/28-modele-coffee
当我在我的网站上选择属性时,url
会发生变化,就像我选择 white color
一样:
example.org/43-product.html#/2-size-s/8-color-white/28-modele-coffee
我想在选择黑色时放置一个背景,并为白色和所有可能的组合放置另一个背景。
我用这个函数来检查url
<script type="text/javascript">
$(document).ready(function () {
if(window.location.href.indexOf("franky") > -1) {
alert("your url contains the name franky");
}
});
</script>
但它只有在我刷新页面时才有效,有没有办法让它工作,以便 url 更改而无需任何刷新?
最佳答案
您可以将 style.css
保存为 style.css.php
并在顶部填充例如:
<?php
header('Content-type: text/css');
$background_color = htmlentities($_GET['background_color'], ENT_QUOTES, 'UTF-8');
?>
/* CSS code goes here */
...或类似的东西。请注意,代码仅作为示例提供,并不安全(如果设置了颜色则丢失,颜色存在...)
关于javascript - 每个特定网址的不同 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42368470/