|
 |
|
การธีมสีของเว็บจากไฟล์ .css และต้องกาารให้จำค่าของ CSS สืบเนื่องไปยังหน้าต่างๆ |
|
 |
|
|
 |
 |
|
เรียน พี่ ๆ ทุกท่าน (ผมเคยสอบถามเรื่องนี้มาแล้วครั้งหนึ่ง แต่ก็ยังทำไม่สมบูรณ์ จึงขออนุญาตมาสอบถามอีกครั้ง)
และขอบคุณมาก ๆ มาที่นี้ด้วยครับ
คือว่า ผมสร้างเว็บหนึ่ง และใช้ style sheet (.css) ให้มีการเลือกธีมสีของตัวอักษร และรายละเอียดตามกำหนดไว้ใน .css ได้
--- จากไฟล์ page1.html ---และต้องการให้สืบเนื่องการจดจำค่าของธีมสีที่เลือกไว้ไปยังไฟล์ page2.html ต่อไป
-----page1.html --------
<html>
<head>
<link id="css" href="red.css" rel="stylesheet">
<script>
function changeTheme(color){
var path = color + '.css';
document.getElementById('css').setAttribute("href",path);
}
</script>
</head>
<body>
<div>
<a href="#" onclick="changeTheme('red')">Red</a>|
<a href="#" onclick="changeTheme('green')">Green</a>|
<a href="#" onclick="changeTheme('blue')">Blue</a>
</div>
<hr>
<span class="txt">TEST Change COLOR CSS</span>
<table width="30%" border="0" cellpadding="2" cellspacing="2" class="brd">
<tr>
<td width="48%"> </td>
<td width="52%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<p><a href="page2.html">หน้าที่ 2</a>
</body>
</html>
--------red.css -------
@charset "windows-874";
/* CSS Document */
body,td,th {
margin-left: 10px;
font:20px tahoma;
}
.txt{
font:40px tahoma;
color:red;
}
.brd{
border: solid 5px black;
background-color:red;
}
-------green.css-------
@charset "windows-874";
/* CSS Document */
body,td,th {
margin-left: 10px;
font:20px tahoma;
}
.txt{
font:40px tahoma;
color:green;
}
.brd{
border: solid 5px black;
background-color:green;
}
-------blue.css-------
@charset "windows-874";
/* CSS Document */
body,td,th {
margin-left: 10px;
font:20px tahoma;
}
.txt{
font:40px tahoma;
color:blue;
}
.brd{
border: solid 5px black;
background-color:blue;
}
-----page2.html --------
<html>
<head>
<link id="css" href="red.css" rel="stylesheet">
<script>
function changeTheme(color){
var path = color + '.css';
document.getElementById('css').setAttribute("href",path);
}
</script>
</head>
<body>
<div>
<a href="#" onclick="changeTheme('red')">Red</a>|
<a href="#" onclick="changeTheme('green')">Green</a>|
<a href="#" onclick="changeTheme('blue')">Blue</a>
</div>
<hr>
<span class="txt">TEST Change COLOR CSS</span>
<table width="30%" border="0" cellpadding="2" cellspacing="2" class="brd">
<tr>
<td width="48%"> </td>
<td width="52%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<p><a href="page1.html">หน้าที่ 1 </a>
</body>
</html>
---- จากรูป ----

----------------------
ผมว่า ตรงส่วนนี้
<link id="css" href="red.css" rel="stylesheet">
จะต้องแก้ไขอย่างไร href="???.css"
Tag : PHP, HTML, CSS

|
ประวัติการแก้ไข 2018-05-31 22:30:14 2018-05-31 22:30:49 2018-05-31 22:31:18 2018-05-31 22:32:15 2018-05-31 22:32:32 2018-05-31 22:33:03
|
 |
 |
 |
 |
Date :
2018-05-31 22:29:24 |
By :
pukmtec |
View :
696 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ session เก็บ ชั่วคราว
ใช้ database เก็บระยะยาว
Code (PHP)
<link href="<?=$_SESSION['theme_file_name']?>.css" >
|
 |
 |
 |
 |
Date :
2018-06-01 08:39:22 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เรียน พี่ Chaidhanan
ต้องแก้ไขตรงนี้หรือเปล่าครับ แต่มันก็ไม่แสดงที่ต้องการเลยครับ รบกวนแนะนำผมด้วยนะครับ ขอบคุณมากครับ
------------------------
<?php
session_start();
?>
<html>
<head>
<link href="<?=$_SESSION['changeTheme']?>.css" id="css" rel="stylesheet">
<script>
function changeTheme(color){
var path = color + '.css';
document.getElementById('css').setAttribute("href",path);
}
</script>
</head>
------------------------------
|
 |
 |
 |
 |
Date :
2018-06-03 23:10:32 |
By :
pukmtec |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้กำหนดชื่อไฟล์ เข้าไปไว้ใน session หรือยังครับ
Code (PHP)
<?php session_start(); ?>
<html>
<head>
<link href="<?=$_SESSION['changeTheme']?>.css" id="css" rel="stylesheet">
</head>
<body>
.....
</body>
</html>
script changeTheme ผมไม่แน่ใจ่ว่ามันจะทำงานหรือเปล่าเพราะไม่เคยทดสอบ css แบบ dynamic
ซึ่งผมไม่แน่ใจว่ามันจะ refresh style sheet ให้เลยหรือไม่
ส่วนใหญ่ที่ทำคือถ้าจะเปลี่ยน ธีม ก็ refresh หน้าใหม่เลย
|
 |
 |
 |
 |
Date :
2018-06-04 08:59:59 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|