Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...