[jQuery] Setting iframe src with $("#iframeid").attr(src,url) adds unwanted item to browser history
This problem happens in both FF 3.0.x, and Safari, on both Windows and
Mac, but not on IE7.
When I set the src of an iframe, it adds another copy of the parent
document's URL to the browser history. This gives the impression of a
broken back button (as the user has to click back twice to go to the
previous page.)
Here's a minimal test case showing that the problem isn't with jQuery,
per se. It happens when I get the element using getElementbyId and
change the src directly.
Is there any way to avoid this back button breaking behavior?
Code sample:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// bypass jQuery
$("#trigger").click(function() {
elt = document.getElementById("targetelt");
if(elt) {
elt.src = "http://google.com";
}
});
// using jQuery
$("#triggerJQ").click(function(e) {
$("#targetelt").attr("src","http://bing.com")
});
});
</script>
</head>
<body>
<!-- use span (styled sort of like a link for fun) to rule out
clicking an href as source of problem -->
<span id="trigger" style="color: blue; text-decoration:
underline;">hello world</span><p/>
<span id="triggerJQ" style="color:blue; text-decoration:
underline;">hello jQuery world</span><p/>
<iframe id="targetelt" width="400" height="300"></iframe>
</body>
</html>
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home