Add ramdom value in argument link

I try to make the argument value “? v=” ramdom on the example below to avoid the cache (Cache-Buster mode) in page Default.aspx

If the page had been in php no problem this is simple but the page is in aspx and so html/javascript I don’t see how to do

<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>

Thank

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

What you can do here is create your object with javascript. Then you will be able to set whatever value in your data attribute.

Replace your body with that (note that I didn’t set every attribute of your object):

   <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>

Method 2

I Solved my prob.

Thank all

<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>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x