0

i add an iframe to my web but everytime it cache the url so the best option for me is everytime to make link like this

http://example.com/ex.html?RANDOMNUMBERS

http://example.com/ex.html?123o8173oy12389

so it will not be cached how can i add example Math.random(); to my url i try this but it doesnt work

<iframe id='iframe2' src="http://example.com/ex.html?<script>Math.random();</script>" frameborder="0" style="overflow: hidden; height: 100%;
    width: 100%; position: absolute;"></iframe>

(i can not use php)

Ba Ta
  • 43
  • 7
  • 1
    What server-side language are you using? – Cerbrus Jul 13 '15 at 14:37
  • Have you looked at this question: http://stackoverflow.com/questions/2648053/preventing-iframe-caching-in-browser Seems to be a FF bug and there's a javascript solution in there – SlashmanX Jul 13 '15 at 14:38
  • you can't embed a script block inside an attribute like that. not possible in any way/shape/form. you CAN have the js code SET the iframe's attribute, e.g. ` – Marc B Jul 13 '15 at 14:39
  • you cannot add javascript in-line like that. If you want to do this purely in javascript, you will need to dynamically create the iframe with `document.createElement`. The alternative is to use server-side code to dynamically output the [static] iframe with the number – CrayonViolent Jul 13 '15 at 14:39
  • How do you add that iframe? Was it loaded along with the page or added via javascript? – lshettyl Jul 13 '15 at 14:40
  • You can also try use new Date().getTime() – Ricardo Pontual Jul 13 '15 at 14:42

2 Answers2

0
function getUrl() {
  return "http://example.com/ex.html?rnd=" + new Date().getTime();
}

using

<iframe id='iframe2' src="javascript:top.getUrl()" frameborder="0" style="overflow: hidden; height: 100%; width: 100%; position: absolute;"></iframe>

I cannot test it here since it blocks on same origin policy when testing

mplungjan
  • 169,008
  • 28
  • 173
  • 236
0

The following should work on its own when put between script tags. No need to create the element using HTML. Doing a console.dir on the iframe variable will show that the source is what we intend to get.

var iframe = document.createElement('iframe');
iframe.src = 'http://example.com/ex.html?' + Math.random();

iframe.style.overflow = 'hidden';
iframe.style.height = '100%';
iframe.style.width = '100%';
iframe.style.position = 'absolute';

document.body.innerHtml += iframe;
Nemery
  • 399
  • 2
  • 11