使用JavaScript打开链接而不点击它

问题陈述: 如何使用JavaScript在不点击链接的情况下打开链接?

null

解决方案: 当鼠标移动到文本上时,链接将打开。它返回一个新创建的窗口,如果调用失败,则返回NULL。

语法:

window.open( URL, name, Specs )

参数: 此函数接受上述三个参数,如下所述:

  • 网址: 它是可选参数。它用于指定需要打开的网页的URL。如果未指定URL,则会打开一个新窗口。
  • 姓名: 它是一个可选参数,用于指定目标属性。
    • _空白: URL将加载到新窗口中。这是可选的。
    • _顶部: URL将替换当前页面。
  • 规格: 这是一个可选参数。这是一个逗号分隔的项目列表,没有空格。
    • 身高: 它以像素为单位表示窗口的高度。
    • 宽度- 它代表像素中窗口的宽度。

注: 允许弹出Web浏览器。

项目1: URL被加载到新窗口中。

<!DOCTYPE html>
< html >
< head >
< title >Javascript open link without click</ title >
< style >
.gfg {
text-align:center;
font-size:40px;
font-weight:bold;
color:green;
}
</ style >
< script >
function myFunction() {
}
</ script >
</ head >
< body >
< div class = "gfg" onmouseover = "myFunction()" >
GeeksforGeeks
</ div >
</ body >
</ html >


输出: clicked image

项目2: URL已加载到当前窗口中。

<!DOCTYPE html>
<html>
<head>
<title>Javascript open link without click</title>
<style>
.gfg {
text-align:center;
font-size:40px;
font-weight:bold;
color:green;
}
</style>
<script>
function myFunction() {
window.open( " https://www.geeksforgeeks.org " , "_top" );
}
</script>
</head>
<body>
<div class = "gfg" onmouseover = "myFunction()" >
GeeksforGeeks
</div>
</body>
</html>


输出: clicked image

方案3: URL被加载到特定大小的新窗口中。

<!DOCTYPE html>
< html >
< head >
< title >Javascript open link without click</ title >
< style >
.gfg {
text-align:center;
font-size:40px;
font-weight:bold;
color:green;
}
</ style >
< script >
function myFunction() {
' ', 'width=500, height=300');
}
</ script >
</ head >
< body >
< div class = "gfg" onmouseover = "myFunction()" >
GeeksforGeeks
</ div >
</ body >
</ html >


输出: clicked image

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享