簡體   English   中英

jquery如何在新窗口中打開可點擊的div

[英]jquery how to make a clickable div open in a new window

我想制作一個沒有內容可點擊的 DIV,因為我使用了這個 jquery 代碼:

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
$("#whole").click(function () {
    window.location = $(this).attr("href");
    });
});

</script>

它工作正常,但鏈接總是在同一個窗口中打開。 我需要如何更改代碼才能在新窗口中打開 div?

$("#whole").click(function () {
   window.open($(this).attr("href"), '_blank');
});

你需要window.open

window.open($(this).attr("href"))
$(document).ready(function() {
$("#whole").click(function () {
    window.open("href"); // window.open('https://stackoverflow.com/questions/13452398/jquery-how-to-make-a-clickable-div-open-in-a-new-window');
    });
});

您可以通過以下方法進行

1)

$(document).ready(function() {
$("#divId").click(function () {
window.open("openThisPage.html"); //Change 'openThisPage.html' to your target page
});
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM