开发者

Does loading unloading iframes in a webpage affects its history?

开发者 https://www.devze.com 2023-02-28 19:23 出处:网络
I have a web page that on click of buttons loads another web page in iframe in a div. On clicking the launch button this is what is done

I have a web page that on click of buttons loads another web page in iframe in a div. On clicking the launch button this is what is done

  • the src attribute of iframe is set to url of required webpage. I have noticed this increments the history.
  • the div is shown, which essentially shows the iframe as well

On clicking the close button

  • the div is hidden, which essentially hides the iframe as well
  • the src attribute of iframe is set to about:blank, de开发者_开发百科leting the iframe object doesn't help

Now this close part increases the browser history and I can see the iframe in history list. Why is this happening and how can I avoid this?

I found the solution. Instead of setting the source attribute one can replace the location with a new url. Example: iframeobject.set contentWindow.document.location.replace(url);


a way to fix the history thing is to not use an iframe but an object and change its data attribute to whatever target. it won't add to history because it's like changing the source of an image. you just have to specify type="text/html" in the object tag

<object type="text/html" data="http://www.google.com/" width="500" height="500"></object>

0

精彩评论

暂无评论...
验证码 换一张
取 消