gpt4 book ai didi

javascript onclick 留下

转载 作者:行者123 更新时间:2023-12-03 01:48:59 28 4
gpt4 key购买 nike

目前,我在单击我的正文时打开一个新选项卡,但它将焦点更改为子窗口。但我想通过留下窗口来做到这一点,这样弹出窗口就不会被阻止,并且我可以将焦点放在当前窗口上。

以下代码当前正在运行

 /**
* For writing cookie
* @param name {String} name of the cookie
* @param value {*} value of the cookie
* @param days {Number} number of days
*/
function setCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

/**
* Get cookie by a name
* @param name {String}
* @returns {*}
*/
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

/**
* Check for already redirected or not. If not then redirect to targeted site.
*/
function redirectToTarget() {
var isAlreadyRedirected = getCookie('redirect');
if (null === isAlreadyRedirected) {
setCookie('redirect', 1, 30); // write for 1 month
window.open('https://www.google.com');
}
}

并从 body onclick 调用 js 函数,如下所示

<body onclick="redirectToTarget()">

任何类型的帮助将不胜感激

最佳答案

在新选项卡中打开您的网站,然后在当前选项卡中重新加载目标 URL。以下 JS 片段可以帮助您。

function redirectToTarget() {
var isAlreadyRedirected = getCookie('redirect');
if (null === isAlreadyRedirected) {
setCookie('redirect', 1, 30); // write for 1 month

var current_loc = window.location.href;
window.location.href = 'https://www.google.com';
window.open(current_loc);
}
}

关于javascript onclick 留下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50504449/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com