Warm tip: This article is reproduced from stackoverflow.com, please click
javascript jquery window.location

Add css only when url is https://mywebsite.com/my-account/return

发布于 2020-03-27 15:39:20

I want to load the following CSS only when window url is https://mywebsite.com/my-account/return

CSS:

<style>.shop table.shop_table.my_account_orders>tbody>tr{
    display: table-row !important;}

.shop table.shop_table.my_account_orders>tbody>tr>td{
    display: table-cell !important;}

.shop table.shop_table.my_account_orders>tbody>tr>td:before{
    display: table-row !important;}</style>
Questioner
Akash Malviya
Viewed
26
semplon 2020-01-31 16:05

if you want to load the style, try this with jquery

<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
      var pageURL = $(location).attr("href");
      console.log(pageURL);
      if( pageURL == 'https://mywebsite.com/my-account/return') {
          $('head').append('<style>.shop table.shop_table.my_account_orders>tbody>tr{\
    display: table-row !important;}\
.shop table.shop_table.my_account_orders>tbody>tr>td{\
    display: table-cell !important;}\
.shop table.shop_table.my_account_orders>tbody>tr>td:before{\
    display: table-row !important;}</style>');
      }
    });
  </script>
</head>
<body>
</body>
</html>