我不知道这是否可能,但我正在try 通过单击一个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>

我想要的是,如果用户点击一个产品,我的网站也会打开一个页面,上面有这样的文字:"你能找到你的产品吗?我们会对你的反馈感兴趣的".

这就是我try 的方式,但没有成功:

<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>

推荐答案

如果我是这么想的,那么最简单的方法就是使用Java脚本,如下例所示.

// 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>

对于新选项卡,它取决于浏览器是否允许显示它.在现代浏览器上,会弹出一个请求访问的窗口

Html相关问答推荐

一次悬停可触发同一分区中的另一次悬停

正文不能填满浏览器100%的高度

如何从卷轴中排除粘性元素?

在悬停时应用文本装饰

如何使VS代码支持以模仿嵌套的方式对已经包含注释的HTML进行注释?

元素offsetTop在滚动容器中时没有更改

`table>;的消失;tbody:nth子级(1)`HTML

仅 Select 悬停的级别,而不 Select 其父级或子级

为什么带有截断的 contentedible div 在受约束时会在 Chrome 中添加空格

视频重新加载而不是在 Swift 中暂停 WKWebView

如何为卡片块制作侧丝带样式

将三个div转换为显示flex

文本不显示在 div 下方

如何消除线性渐变线的模糊?

如何通过像图像一样的 元素来调整 SVG 图标的大小

表格中每 4 行条纹一次

如何使用 CSS 使粘性元素固定在视口顶部

文本输入在 Chrome 中保持水平滚动,带有文本溢出:省略号

水平滚动框不显示所有元素

用 flexbox 和 overflow 覆盖