EDIT: I am not talking about the status bar display, I’m talking about the text you click on to follow the link. /EDIT
I looked through a few similar posts and didn’t find an answer. I have a link that I want displayed.
I want the href of the link to change every time the link is clicked.
href=”www.mylink.com?R=340978″
The query string changes to a random number after each click to prevent the browser from caching the page. It’s expected that the page will be changing frequently and be viewed frequently to assess those changes.
So I want people to see “www.mylink.com” but the link to lead to “www.mylink.com?R=34532” I thought I would achieve this with an onclick event that would apend a new random number and set the href attribute to the new link, however this is also changing the text that is displayed.
<script type="text/javascript">
var baseLink = "http://myDevLink/library/ea26098f-89d1-4305-9f75-afc7937f8336/25/test/036b602b-0bde-e011-957b-1cc1dee8bacd.html";
var link = "";
// Prime the link
$(document).ready(function()
{
NewRandomParam();
});
function NewRandomParam()
{
// Make sure one of the warning messages isn't displayed instead of the link
if (document.getElementById("link") != null)
{
// Add a random number param to the query string to prevent the user from opening a cached version of the page
link = baseLink + "?R=" + Math.floor(Math.random() * 1000000);
document.getElementById("link").setAttribute("href", link);
}
}
</script>
<body>
<div id="divContent" style="display:inline; border:0px" class="tab">
<pre style="margin-top: 0;" >
<font face="tahoma">
<a href="" id="link" onclick=NewRandomParam(); target="_blank">http://myDevLink/library/ea26098f-89d1-4305-9f75-afc7937f8336/25/test/036b602b-0bde-e011-957b-1cc1dee8bacd.html</a>
</font>
</pre>
</div>
</body>
</html>
As you can see from the above code, there is no query string on what should be displayed however when I view the page the value of the href is displayed with the query string. If I do a view source the correct url is there and should be displayed but it isn’t.
Please enlighten me on where I’m being dumb.
The solution was a combination of things suggested here plus having to reset the links text to what I wanted it. Here is what worked.
Thanks to all of you.