我不知道是否可能,但我试图通过单击HTML元素来打开页面。我在下面详述。
我有一个HTML网页与一个第三方工具的源代码(一个产品的代销商购买代码)。因此,当用户单击此代码中的某个产品时,他将被重定向到第三方商家。让我们想象一下下面的代码:
<head>
<script async defer src="[linkremoved]"></script>
</head>
<body>
<!-- my page content -->
<div>
<!-- Partner code -->
<div data-gyg-href="[linkremoved]" data-gyg-locale-code="fr-FR" data-gyg-q="Neuhausen"></div>
</div>
<!-- my page content -->
</body>我想要的是,如果用户点击一个产品,我的网站也会打开一个页面,上面写着“你能找到你的产品吗?我们会对你的反馈感兴趣”。
我就是这么试的,但都没成功:
<head>
<script async defer src="[linkremoved]"></script>
</head>
<body>
<!-- my page content -->
<a href ="comments.html" target="_blank">
<div>
<!-- Partner code -->
<div data-gyg-href="[linkremoved]" data-gyg-locale-code="fr-FR" data-gyg-q="Neuhausen"></div>
</div></a>
<!-- my page content -->
</body>发布于 2022-08-23 09:52:09
如果我认为最简单的方法就是使用javascript,例如下面的例子。
// If you want to redirect user without opening a new tab, use this
// window.location.href="https://example.com";
// But if you want to open a new tab, use this
// window.open("https://www.example.com", "_blank");
function noNewTab() {
window.location.href="https://example.com";
}
function newTab() {
window.open("https://www.example.com", "_blank");
}
function localFile() {
// First we will need to get the url of your webpage
let currentUrl = window.location.origin;
// To what file redirect?
let redirectFile = "test.html";
// And redirect. We will need to add / before the file path
window.location.href = currentUrl + "/" + redirectFile;
}<div onclick="noNewTab()">
<p> Example product. Click on me! (No new tab) </p>
</div>
<div onclick="newTab()">
<p> Example product. Click on me! (New tab) </p>
</div>
<div onclick="localFile()">
<p> Example product. Click on me! (Change file, not url) </p>
</div>
对于新的选项卡,它依赖于浏览器,如果它允许显示它。在现代浏览器上,有请求访问的弹出。
发布于 2022-08-23 10:39:30
一种可能的方法是将target="_blank"与单击处理程序一起使用,如
<a href="https://www.w3schools.com" target="_blank" onclick="yourfunction()">Visit W3Schools</a> 如果需要以编程方式触发此操作,则可以:
window.open(yoururl);
//Your further code...发布于 2022-08-23 09:08:33
我认为您应该尝试使用span而不是div标记,或者可能是p标记。
<a href ="comments.html" target="_blank">
<span>
< HERE IS THE PARTNER CODE >
</span>
</a>https://stackoverflow.com/questions/73455880
复制相似问题