Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Learn More

Javascript command window.getComputedStyle(document.body, ':after').getPropertyValue('content') returns content with extra double quotes

  • 1 trả lời
  • 2 gặp vấn đề này
  • 13 lượt xem
  • Trả lời mới nhất được viết bởi cor-el

more options

When I use in my css: body:after { content: "mobile"; display: none; } And check this with javascript with the command: var size = window.getComputedStyle(document.body, ':after').getPropertyValue('content');

I get in firefox (v 23.0.1 mac) returned the string ""mobile"" with doubled quotes as return and therefore the check if size =="mobile" returns false. In safari the value returned "mobile" without the doubles quotes. How come?

When I use in my css: body:after { content: "mobile"; display: none; } And check this with javascript with the command: var size = window.getComputedStyle(document.body, ':after').getPropertyValue('content'); I get in firefox (v 23.0.1 mac) returned the string ""mobile"" with doubled quotes as return and therefore the check if size =="mobile" returns false. In safari the value returned "mobile" without the doubles quotes. How come?

Giải pháp được chọn

What you get is a string that represents of what you specified in content.

A content specification can include other things like a counter: body:after { content: "topics[" counter(topics) "]"; }

size = window.getComputedStyle(document.body, ':after').content would give: "topics[" counter(topics) "]"
So you need to test for the exact text of the content: size=='"mobile"';

Đọc câu trả lời này trong ngữ cảnh 👍 0

Tất cả các câu trả lời (1)

more options

Giải pháp được chọn

What you get is a string that represents of what you specified in content.

A content specification can include other things like a counter: body:after { content: "topics[" counter(topics) "]"; }

size = window.getComputedStyle(document.body, ':after').content would give: "topics[" counter(topics) "]"
So you need to test for the exact text of the content: size=='"mobile"';