Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript更改框架的URL_Javascript_Html_Frames - Fatal编程技术网

使用Javascript更改框架的URL

使用Javascript更改框架的URL,javascript,html,frames,Javascript,Html,Frames,我的页面中有两个框架frame1和frame2。第2帧显示一个名为rightpage.html的html页面。因此,当我单击frame2上的rightpage.html时,它需要将frame1URL的URL更改为toppage.html <html> <frameset cols='45%,55%'> <frame src='leftpage.html' name='frame1' id='frame1' frameborder='0'>

我的页面中有两个框架
frame1
frame2
。第2帧显示一个名为
rightpage.html
的html页面。因此,当我单击
frame2
上的
rightpage.html
时,它需要将
frame1
URL的URL更改为
toppage.html

<html>
    <frameset cols='45%,55%'>
        <frame src='leftpage.html' name='frame1' id='frame1' frameborder='0'>
        <frame src='rightpage.html' name='frame2' id='frame2' frameborder='0'>
    </frameset>
</html>

你能帮忙吗


提前感谢。

如果您想使用JavaScript解决方案,可以使用以下代码段:

parent.frame1.location = 'toppage.html'
您还可以使用锚定的
target
属性。比如说

<a href="toppage.html" target="frame1">Link text</a>


PS:对于现代网站或web应用程序来说,使用框架并非明智之举,我希望您对此有充分的理由。

很好地回答了这个问题,并且仍然建议在现代浏览器中不要使用框架。