帮助:从href链接更改ilayer src ... [英] HELP: Changing ilayer src from a href link...
问题描述
我正在尝试从
ilayer内的链接更改父文档中ilayer的src。我无法让它发挥作用。发生的一切都是Netscape 4崩溃。这只是Netscape 4的
。
例如,这是主页:
< html>
< head>
< script type =" text / javascript">
function updateILayer(obj){
parent.document.layers [" layer1"]。src = obj.href;
}
< / script>
< / head>
< body>
< ilayer name =" layer1" ID = QUOT;层1" src =" home.htm">
< / ilayer>
< / body>
< / html>
这里是home.htm src:
< html>
< head>
< / head>
< body>
点击此链接进入测试页面:
< a onClick =" parent.updateILayer(this);" href =" test.htm"> test< / a>
< / body>
< / html>
这里是test.htm src:
< html>
< head>
< / head>
< body>
点击此链接转到主页:
< a onClick = QUOT; parent.updateILayer(本);" href =" home.htm"> home< / a>
< / body>
< / html>
I''m trying to change the src of an ilayer in the parent document from a link inside the
ilayer. I''m not able to get it to work. All that happens is Netscape 4 crashes. This is
for Netscape 4 only.
For example, here is the main page:
<html>
<head>
<script type="text/javascript">
function updateILayer(obj) {
parent.document.layers["layer1"].src = obj.href;
}
</script>
</head>
<body>
<ilayer name="layer1" id="layer1" src="home.htm">
</ilayer>
</body>
</html>
And here''s the home.htm src:
<html>
<head>
</head>
<body>
Click this link to go to test page:
<a onClick="parent.updateILayer(this);" href="test.htm">test</a>
</body>
</html>
And here''s the test.htm src:
<html>
<head>
</head>
<body>
Click this link to go to home page:
<a onClick="parent.updateILayer(this);" href="home.htm">home</a>
</body>
</html>
推荐答案
好吧,为了防止它在你点击链接时崩溃,我已经改变了这个功能:
function updateILayer(obj){
eval(" parent.document.layer1.src =" + obj.href);
}
但它仍然无法正常工作。它只是去那个链接,并没有改变ilayer src。我
可以判断,因为我已添加< hr>围绕< ilayer>所以,如果ilayer src被更改,则
< hr>仍然会在那里。
Brandon Hoppe写道:
Well, to keep it from crashing when you click on the link, I''ve change the function as such:
function updateILayer(obj) {
eval("parent.document.layer1.src=" + obj.href);
}
But it still doesn''t work. It just goes to that link and doesn''t change the ilayer src. I
can tell because I''ve add <hr> around the <ilayer> so if the ilayer src is changed then
the <hr> would still be there.
Brandon Hoppe wrote:
我正在尝试更改父文档中ilayer的src在ilayer中的链接。我无法让它发挥作用。发生的一切
是Netscape 4崩溃。这仅适用于Netscape 4.
例如,这是主页:
< html>
< head>
< script type =" text / javascript">
function updateILayer(obj){
parent.document.layers [" layer1"]。src = obj.href;
}
< / script>
< / head>
< body>
< ilayer name =" layer1" ID = QUOT;层1" src =" home.htm">
< / ilayer>
< / body>
< / html>
这里's' home.htm src:
< html>
< head>
< / head>
< body>
点击此链接转到测试页面:
< a onClick =" parent.updateILayer(this);" href =" test.htm"> test< / a>
< / body>
< / html>
这里是test.htm src:
< html>
< head>
< / head>
< body>
点击此链接转到主页:
< a onClick =" parent.updateILayer(this);" href =" home.htm"> home< / a>
< / body>
< / html>
I''m trying to change the src of an ilayer in the parent document from a
link inside the ilayer. I''m not able to get it to work. All that happens
is Netscape 4 crashes. This is for Netscape 4 only.
For example, here is the main page:
<html>
<head>
<script type="text/javascript">
function updateILayer(obj) {
parent.document.layers["layer1"].src = obj.href;
}
</script>
</head>
<body>
<ilayer name="layer1" id="layer1" src="home.htm">
</ilayer>
</body>
</html>
And here''s the home.htm src:
<html>
<head>
</head>
<body>
Click this link to go to test page:
<a onClick="parent.updateILayer(this);" href="test.htm">test</a>
</body>
</html>
And here''s the test.htm src:
<html>
<head>
</head>
<body>
Click this link to go to home page:
<a onClick="parent.updateILayer(this);" href="home.htm">home</a>
</body>
</html>
Brandon Hoppe< bh **** @ ti.com>写道:
Brandon Hoppe <bh****@ti.com> writes:
好吧,为了防止它在你点击链接时崩溃,我已经改变了这个功能:
函数updateILayer(obj) ){
eval(" parent.document.layer1.src =" + obj.href);
}
不要使用" eval,永远。有更好的方法可以做你想要的事情
(其中有几个更好:更短,更快,使用更少的内容,并且更容易出错)。例外情况很少而且很少见,你不可能偶然发现一个。
如果obj.href包含http:// www .example.com",你上面的构造
将尝试评估以下字符串:
" parent.document.layer1.src = http://www.example .com"
请注意,在=之后部件周围没有引号,所以
只是一个很大的语法错误。
尝试:
parent.document.getElementById(" layer1")。src = obj.h ref
(图层通常不用全局变量表示,你需要
才能找到它们。)
您可能也可以这样做:
parent.layers [" layer1"]。location.href = obj.href;
但它仍然无法正常工作。它只是去那个链接,并没有改变ilayer src。
猜猜:你需要返回假。
我可以说,因为我已添加< hr>围绕
< ilayer>因此,如果更改了ilayer src,那么< hr>仍然会在那里。
Well, to keep it from crashing when you click on the link, I''ve change the function as such:
function updateILayer(obj) {
eval("parent.document.layer1.src=" + obj.href);
}
Don''t use "eval", ever. There are better ways to do what you want
(where better is several of: shorter, faster, uses less momory, and is
less error prone). The exceptions are so few and rare, that you are
unlikely to hit one by accident.
If obj.href contains "http://www.example.com", your construction above
will try to eval the following string:
"parent.document.layer1.src=http://www.example.com"
Notice that there are no quotes around the part after the "=", so
it is just one big syntax error.
Try:
parent.document.getElementById("layer1").src=obj.h ref
(layers are generally not represented by global variables, you need
to find them the hard way).
You could probably also do:
parent.layers["layer1"].location.href = obj.href;
But it still doesn''t work. It just goes to that link and doesn''t
change the ilayer src.
Guess: you need to return false.
I can tell because I''ve add <hr> around the
<ilayer> so if the ilayer src is changed then the <hr> would still be
there.
< a onClick =" parent.updateILayer(this);" href =" test.htm"> test< / a>
<a onClick="parent.updateILayer(this);" href="test.htm">test</a>
是的,请记得返回false:
< a href =" test.htm"
onclick =" parent.updateILayer(this); return false"> test< / a>
返回false阻止链接正常运行(以下
)。
/ L
-
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML死亡颜色:< URL:http:/ /www.infimum.dk/HTML/rasterTriangleDOM.html>
''没有判断的信仰只会降低精神神圣。''
Yep, remember to return false:
<a href="test.htm"
onclick="parent.updateILayer(this);return false">test</a>
Returning false prevents the normal operation of the link (following
it).
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
''Faith without judgement merely degrades the spirit divine.''
Lasse Reichstein Nielsen写道:
Lasse Reichstein Nielsen wrote:
永远不要使用eval。有更好的方法可以做你想要的事情
(其中几个更好:更短,更快,使用更少的内容,并且不易出错)。例外很少且很少见,你不可能偶然遇到一个。
如果obj.href包含http://www.example.com" ;,你的结构上面
将尝试评估以下字符串:
" parent.document.layer1.src = http://www.example.com"
请注意,部件周围没有引号在=之后,所以
只是一个很大的语法错误。
是的,我从未使用过eval,但此时我只是在尝试任何事情。
尝试:
父母.document.getElementById(" layer1")。src = obj.h ref
(图层通常不用全局变量表示,你需要
来找到它们的难点)。
Nope。
您可能也可以这样做:
parent.layers [" layer1"]。location.href = obj.href;
Nope。
是的,记得返回false:
< a href =" test.htm"
onclick = " parent.updateILayer(this); return false"> test< / a>
返回false会阻止链接的正常操作(在
之后)。
Don''t use "eval", ever. There are better ways to do what you want
(where better is several of: shorter, faster, uses less momory, and is
less error prone). The exceptions are so few and rare, that you are
unlikely to hit one by accident.
If obj.href contains "http://www.example.com", your construction above
will try to eval the following string:
"parent.document.layer1.src=http://www.example.com"
Notice that there are no quotes around the part after the "=", so
it is just one big syntax error.
Yeah, I''ve never used eval but I was just trying anything at this point.
Try:
parent.document.getElementById("layer1").src=obj.h ref
(layers are generally not represented by global variables, you need
to find them the hard way).
Nope.
You could probably also do:
parent.layers["layer1"].location.href = obj.href;
Nope.
Yep, remember to return false:
<a href="test.htm"
onclick="parent.updateILayer(this);return false">test</a>
Returning false prevents the normal operation of the link (following
it).
哦是的,忘记归还假。好的,我添加了返回false,但它仍然只是链接到
。我在函数调用中尝试了这些行,但都没有工作:
parent.document.layer1.src = obj.href;
parent.document .getElementById(" layer1")。src = obj.h ref;
parent.document.layers [" layer1"]。src = obj.href;
parent.layers [" layer1"]。location.href = obj.href;
我读过你可以更改ilayer src链接但我还没有看到它完成了大声笑:)
Oh yeah, forgot to return false. Ok, I''ve added return false but it still just goes to
that link. I''ve tried these lines in the function call but neither worked:
parent.document.layer1.src=obj.href;
parent.document.getElementById("layer1").src=obj.h ref;
parent.document.layers["layer1"].src=obj.href;
parent.layers["layer1"].location.href=obj.href;
I''ve read you can change the ilayer src link but I haven''t seen it done yet lol :)
这篇关于帮助:从href链接更改ilayer src ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!