By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

[Netscape] href in iframe hangs when calling function in parent window

P: n/a
Hi,

the following code has the mentioned behaviour:

<html>
<head>
<script type="text/javascript">
function newA() {
for (i=0;i<3;i++) {
var a = window.frames[0].document.createElement("a");
a.innerHTML = "anchor "+i;
a.setAttribute("innerHTML", "anchor "+i);
a.setAttribute("href", "javascript:parent.h_click()");
window.frames[0].document.body.appendChild(a);
}
}
function h_click() {
alert('ciao!');
}
</script>
</head>
<body>
<input type="button"
onclick="document.body.appendChild(document.create Element('iframe'))"
value="new iFrame">
<input type="button" onclick="newA()" value="new anchor">
</body>
</html>
The same stuff adapted to IE6 works.

Suggestions?

Thnx,

Christian

Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Christian Radermacher wrote:
Hi,

the following code has the mentioned behaviour:

<html>
<head>
<script type="text/javascript">
function newA() {
for (i=0;i<3;i++) {
var a = window.frames[0].document.createElement("a");
a.innerHTML = "anchor "+i;
a.setAttribute("innerHTML", "anchor "+i);
a.setAttribute("href", "javascript:parent.h_click()");
window.frames[0].document.body.appendChild(a);
}
}
function h_click() {
alert('ciao!');
}
</script>
</head>
<body>
<input type="button"
onclick="document.body.appendChild(document.create Element('iframe'))"
value="new iFrame">
<input type="button" onclick="newA()" value="new anchor">
</body>
</html>

The same stuff adapted to IE6 works.

Suggestions?

Thnx,

Christian


<script type="text/javascript">
function newA() {
for (i=0;i<3;i++) {
var a = window.frames[0].document.createElement("a");
var t = window.frames[0].document.createTextNode("anchor" + i);
a.setAttribute("href", "#");
a.onclick = parent.h_click;
a.appendChild(t);
window.frames[0].document.body.appendChild(a);
}
}
function h_click() {
alert('ciao!');
return false;
}
</script>

Works in Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5b)
Gecko/20030904

Note that you shouldn't be setting HREF to "javascript:..." <url:
http://jibbering.com/faq/#FAQ4_24 /> and you should be returning false
from the onclick event.

Oddly enough, the links don't appear with the correct text decoration in
the version of Mozilla I tested it in. Nor does the mouse cursor change
when I roll over them. However, when clicked, they do alert "ciao!".

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.