如何隐藏HTML元素仅显示在桌面的其他页面上?

时间:2016-04-26 17:40:27

标签: javascript jquery html hide

我的情况是我通过CMS创建网站并使用页面包装器。页面包装器css / html等将适用于所有页面,因此如果我创建了一个名为“Start a Fundraiser”的自定义按钮,则此按钮将显示在所有页面上。我想知道是否有一个javascript方法或其他东西可以将其隐藏在其他页面中或强制它只出现在问候页面中,最好仅应用于桌面,只有它在手机上显示的方式看起来很棒,但如果这让它变得复杂,我也可以将它隐藏在移动版的其他页面上。

Test Page< ==我的测试页面如果您转到“了解更多”标签并打开下拉菜单,“开始筹款按钮”会从其所在位置拉下来。

现在CMS确实能够创建各种条件语句,但这是最令人困惑的事情,这是一个例子:

Simple Tests
If the test case matches, do one thing or do nothing:
[[?xx[[S1:first_name]]xx::xxBobxx::Hi, Bob!::]]
If the first_name is Bob, render "Hi, Bob!", if not, render nothing.
If the test case matches, do one thing or do another thing:
[[?xx[[S1:first_name]]xx::xxBobxx::Hi, Bob!::Hello.]]
If the first_name is Bob, render "Hi, Bob!", if not, render "Hello."

现在有超过100个S标签,并且没有一个专门说“隐藏”或类似的东西,所以它需要一段时间才能通过它们,因为它们有非常通用的标题,所以在同一时间我希望有某种解决方案来加快速度。

他们的客户服务没有帮助大声笑,给了我上面发布的代码的链接。

编辑 我注意到CMS可能使用PHP,但我无法访问任何html文档,所以我不能检查是否正在使用php标签。但是在页面包装器中,我可以使用此S-tag命令调用我需要的HTML文档:

[[S63:3]]

它拉动了所有的身体内容。所以这就是为什么我不知道它是否使用PHP。 CMS系统称为Luminate Online(现在由Blackbaud拥有)

这是一个关于如何插入数据的图像,以及如何制作页面包装器。它左边是HTML Body,但它不是,它基本上是一个样式包装器,可以应用于任何使用它的html页面,无论是谁设置它都创建了其他地方无法访问的内容,并且该人不再与我们在一起。

Page Wrapper

如果您需要任何其他信息,请随时询问!我将尽我所能!

任何建议都表示赞赏!谢谢你的时间。

2 个答案:

答案 0 :(得分:3)

这是一个JavaScript解决方案,假设您的按钮具有ID:

    // Set your target url
    var url = 'http://yourdomain.com/targeturl';

    if ( document.URL == url ){
        // If it is the target show the button
        document.getElementById("x").style.display = 'block';
    }else{
        // If it is not the target page hide the button
        document.getElementById("x").style.display = 'none !important';   
    }

一种CSS解决方案,用于隐藏除桌面以外的所有设备宽度上的按钮:

   #x {
      display: none;
   }
   @media ( min-width: 992px ) {
      #x {
         display: block;
      }
   }

务必将"x"更改为按钮的ID。

以下是具有特定URL和ID的jQuery替代方法:

    var url = "http://convio.cancer.ca/site/TR?fr_id=21959&pg=entry";
    if ( window.location.href == url ){
        $( '#hmpgonly').css( 'display', 'block' );
    } else {
        $( '#hmpgonly').css( 'display', 'none !important' );
    }

在该页面上,它将显示按钮,在其他所有按钮上应该将其删除。我在页面加载后在你的控制台中对此进行了测试。

答案 1 :(得分:1)

看起来你正在使用PhP,所以你可以做这样的事情。

显示所有网页,但“/ site / TR / Events / General /”one

if ($_SERVER['SCRIPT_NAME'] != '/site/TR/Events/General/index.php') {
    ///code here
}

只在“/ site / TR / Events / General /”页面上显示

if ($_SERVER['SCRIPT_NAME'] == '/site/TR/Events/General/index.php') {
    ///code here
}

我喜欢使用$_SERVER['SCRIPT_NAME'],因为它显示了消除/dir/?this=that&that=this等动态路径问题的基本路径。

相关问题