【问题标题】:Add ramdom value in argument link在参数链接中添加随机值
【发布时间】:2021-04-13 04:13:29
【问题描述】:

我尝试在下面的示例中设置参数值 "?v=" ramdom 以避免页面 Default.aspx 中的缓存(Cache-Buster 模式)

如果页面是 php 没问题,这很简单,但页面是 aspx 和 html/javascript 我不知道该怎么做

<Html>
<Head>
<meta Http-Equiv="Cache" content="no-cache">
<meta Http-Equiv="Pragma-Control" content="no-cache">
<meta Http-Equiv="Cache-directive" Content="no-cache">
<meta Http-Equiv="Pragma-directive" Content="no-cache">
<meta Http-Equiv="Cache-Control" Content="no-cache">
<meta Http-Equiv="Pragma" Content="no-cache">
<meta Http-Equiv="Expires" Content="0">
<meta Http-Equiv="Pragma-directive: no-cache">
<meta Http-Equiv="Cache-directive: no-cache">
</Head>
<Body>
<marquee><object width="910" height="50" type="text/plain" data="http://sandbox.serveur.prive/test.txt?v=[Here-Value-Ramdom]" border="0" style="overflow: hidden;"></object></marquee>
</Body>
</Html>

谢谢

【问题讨论】:

  • "但是页面是 aspx 和 html/javascript" - 问题是什么?找到一种方法来生成随机数并添加它(使用您想要执行此操作的语言)。
  • &lt;marquee&gt; 已弃用

标签: javascript html asp.net caching


【解决方案1】:

您可以在这里做的是使用 javascript 创建您的对象。然后你就可以在你的数据属性中设置任何值了。

用那个替换你的身体(注意我没有设置你对象的每个属性):

   <body>
     <script>
       // create the object
       const obj = document.createElement("object");
       obj.width = "910"
       obj.height= "50"
       // add any other attributes like that
       // obj.type = ....
       // obj.boder = ..

       // just using a simple random here, but you can probably generate a string also
       obj.data = "http://sandbox.serveur.prive/test.txt?v=" + Math.random()
       // add the element to the body
       document.body.appendChild(obj);
     </script>
   </body>

【讨论】:

  • 谢谢@AzloD 我没有更新页面并看到你的答案,现在我感谢你的回答,但如果可能的话,我会寻求更通用的东西,让我可以将变量 ramdom 添加到不同的链接任何页面,而不仅仅是“对象”的链接,有点像下面答案中所示的 PHP 示例。如果可以的话?
【解决方案2】:

我解决了我的问题。

谢谢大家

<html>
    <head>
        <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
        <meta Http-Equiv="Cache" content="no-cache">
        <meta Http-Equiv="Pragma-Control" content="no-cache">
        <meta Http-Equiv="Cache-directive" Content="no-cache">
        <meta Http-Equiv="Pragma-directive" Content="no-cache">
        <meta Http-Equiv="Cache-Control" Content="no-cache">
        <meta Http-Equiv="Pragma" Content="no-cache">
        <meta Http-Equiv="Expires" Content="0">
        <meta Http-Equiv="Pragma-directive: no-cache">
        <meta Http-Equiv="Cache-directive: no-cache">
    </head>
    <body>
        <div id="webLink">
            <div id="DivAlertePageLogin">
                <marquee>
                        <object id="ObjAlertePageLogin" width="300" height="100" type="text/plain" data="test.txt" border="0" style="overflow: hidden;"></object>
                </marquee>
            </div>
        </div>
        <script type="text/javascript">
            var newUrl = 'Alerte_PageLogin1.txt';
            var divEl = document.getElementById('DivAlertePageLogin');
            var objEl = document.getElementById('ObjAlertePageLogin');
            objEl.data = newUrl;
            // Refresh the content
            divEl.innerHTML = divEl.innerHTML;
        </script>
    </body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-02
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 2023-04-04
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多