我不知道這是否可能,但我試圖通過單擊 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>
uj5u.com熱心網友回復:
如果這是我認為最簡單的方法就是使用 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>
使用新選項卡取決于瀏覽器是否允許顯示它。在現代瀏覽器上會彈出請求訪問
uj5u.com熱心網友回復:
一種可能的方法是target="_blank"
與單擊處理程式一起使用,例如
<a href="https://www.w3schools.com" target="_blank" onclick="yourfunction()">Visit W3Schools</a>
如果您需要以編程方式觸發此操作,則可以:
window.open(yoururl);
//Your further code...
uj5u.com熱心網友回復:
我認為您應該嘗試使用 span 而不是 div 標簽或 ap 標簽
<a href ="comments.html" target="_blank">
<span>
< HERE IS THE PARTNER CODE >
</span>
</a>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/505688.html