Javascript 如何根据查询字符串在页面上显示内容?

Javascript 如何根据查询字符串在页面上显示内容?,javascript,html,css,query-string,Javascript,Html,Css,Query String,我与一个使用供应商基于web的应用程序的团队合作。当人们注销时,他们会被重定向到登录页面,我们想在那里添加一条消息。我们没有权限更改代码(它是云托管的),但我们可以在URL中传递查询字符串参数 我们可以这样做: http://our.site.com?logout=true 从那里,我想用h2或其他格式显示一条消息 我们可以自定义页面的HTML、CSS和JS,但是我们没有访问应用程序源代码的权限(否则我会用PHP实现) 我想我可以使用JS来改变一些CSS,但是在我所有的试验中,我都不能让CSS

我与一个使用供应商基于web的应用程序的团队合作。当人们注销时,他们会被重定向到登录页面,我们想在那里添加一条消息。我们没有权限更改代码(它是云托管的),但我们可以在URL中传递查询字符串参数

我们可以这样做:

http://our.site.com?logout=true
从那里,我想用h2或其他格式显示一条消息

我们可以自定义页面的HTML、CSS和JS,但是我们没有访问应用程序源代码的权限(否则我会用PHP实现)


我想我可以使用JS来改变一些CSS,但是在我所有的试验中,我都不能让CSS真正改变

试试看!更改CSS很重要吗?只是一个临时解决方案,直到您可以编辑实际代码。

检查此答案:


从上面的问题中,我了解到您需要一段代码,根据收到的查询字符串在登录页面上显示一些消息。以下是您可以添加到登录页面html页脚中的代码(因为您可以访问html)


注意:仔细阅读代码注释,根据您的html结构编辑代码。

请添加一些您试图使其正常工作的代码片段。这样我们才能准确地了解你的处境。谢谢!这是唯一有实际帮助的评论。
var logout = getUrlParameter('logout');
if(typeof logout !== "undefined")
{
  // show some div with display: none
  // or put some content to the existing div
} 
<script type="text/javascript">
    function getParamValue(querystring) {
          var qstring = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
          for (var i = 0; i < qstring.length; i++) {
            var urlparam = qstring[i].split('=');
            if (urlparam[0] == querystring) {
               return urlparam[1];
            }
          }
    }
    if(getParamValue('logout')=='true'){
         var messageDiv = document.createElement("div");       // Creating a div to display your message
         var message = document.createTextNode("You have successfully logged out.");  // Preparing the message to show
         messageDiv.appendChild(message);                     // Appended the message in newly created div

         var addIn = document.getElementById("login");       //just presuming there is a div having id="login" in which you want to prepend the message
         addIn.insertBefore(messageDiv, addIn.childNodes[0]); //just appended the message on top of login div
         //setting style in your message div
         messageDiv.style.backgroundColor ="#FF0000";
         messageDiv.style.width ="100%";
    }
    </script>
http://our.site.com/login.php?logout=true