在自身窗口中使用JavaScript打开URL

fiei3ece  于 2023-01-07  发布在  Java
关注(0)|答案(2)|浏览(162)
<SCRIPT language="JavaScript1.2">
function openwindow()
{
    window.open("http://www.javascript-coder.com","mywindow","menubar=1,resizable=1,width=350,height=250");
}
</SCRIPT>
<P>
<A href="javascript: openwindow()">Open the JavaScript Window Example 1</A>
</P>

这是一个在新窗口中打开URL的例子。我怎样才能让它在同一个窗口中打开呢?类似于target=self

f2uvfpb9

f2uvfpb91#

简单地使用一个锚,它是什么:

<A href="http://www.javascript-coder.com">Open the link</A>

不需要javascript;)
然而,当前窗口的设置(菜单条,滚动条等)不能被javascript改变.这只能在新建窗口中才能改变.
如果您确实需要使用window.location

function openLink()
 {
     window.location.href = "http://www.javascript-coder.com";
 }
nimxete2

nimxete22#

就这么办吧:

<SCRIPT language="JavaScript1.2">
   window.location.href="http://www.javascript-coder.com";
</SCRIPT>

这将把当前窗口的位置赋给url,类似于self = target。

相关问题