2014-10-02 86 views
-2

想知道是否有可能隱藏或顯示基於多個URL的內容?根據多個網址隱藏/顯示內容

例如,用戶在家或索引與www.url.com/或www.url.com/index.html

特定元素display: blockdisplay: none

if(location=="http://domain.com/") { 

偉大的作品,但我怎麼能指定多個URL上面類似的格式相同嗎?

回答

1
if(location=="http://google.com") { 
    //Do something here 
} else { 
    //Do something else here 
} 
+0

謝謝!不知道爲什麼我會陷入低谷,只是從來沒有嘗試過這種技術。感謝壽 – 2014-10-02 20:59:31

0

通過測試location.pathname這樣的:

document.getElementById('specific').style.display = location.pathname === "/index.html" ? 'none' : 'block'; 
+1

這不提供問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 – 2014-10-02 21:09:37

+1

好吧然後我改變它 – OxyDesign 2014-10-02 21:58:05

0

您可以使用PHP到$_GET URL信息。比方說,你有以下網址:

https://www.wherever.com/some_file.php?css1=1&css2=1 

在另一個時間,讓我們假設URL看起來像:

https://www.wherever.com/some_file.php?css3=1&css4=1 

當你寫一個生成HTML的PHP​​頁面:

<?php 
$css = ''; 
function link_builder(){ 
    $a = func_get_args(); $lo = "<link rel='stylesheet' type='text/css' href='"; $lc = "' />"; $o = ''; 
    foreach($a as $v){ 
    $o .= "$lo$v$lc"; 
    } 
    return $o; 
} 
if(isset($_GET['css1'], $_GET['css2']) && $_GET['css1'] === '1' && $_GET['css2'] === '1'){ 
    $css = link_builder('cssPath1.css', 'cssPath2.css'); 
} 
if(isset($_GET['css3'], $_GET['css4']) && $_GET['css3'] === '1' && $_GET['css4'] === '1'){ 
    $css = link_builder('cssPath3.css', 'cssPath4.css'); 
} 
echo $css; 
?> 

使用此方法,您可以預先創建單獨的外部CSS文件,這些文件可以緩存到客戶端的瀏覽器內存中。 JavaScript風格不會那樣做。