最奇怪的事情正在发生。此单击事件将打开一个空白的新选项卡,然后在原始选项卡中导航到正确的页面。发生了什么,我该如何解决?
我检查了检查员的目标=" _blank"可能之前添加的属性,没有任何内容。我在我的代码中搜索了它并没有。因此,window.open上的_blank属性将打开一个空白的新选项卡并导航到同一选项卡中的URL是没有意义的。
感谢。
$(".homedepot, .amazon, .walmart").on('click', function() {
url = $(this).attr('href');
window.open(url , "_blank");
trackOutboundLink(url);
});
//var path = window.location.path;
var trackOutboundLink = function(url) {
var loc = function getLocation(url) {
var match = href.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
return match && {
href: href,
protocol: match[1],
host: match[2],
hostname: match[3],
port: match[4],
pathname: match[5],
search: match[6],
hash: match[7]
}
}
newURL = loc.protocol + "//" + loc.host;
console.log(newURL)
ga('send', 'event', 'outbound click', 'click', newURL, {
'transport': 'beacon',
'hitCallback': function(){console.log("");}
});
}
标记:
<a class="ilHide" href="<%= product.data["product.buy_amazon"].value[0].text %>"><img class="amazon" style="width:200px; position: relative; right: .5rem;" src="images/amazon2.jpeg" alt="Amazon" /></a>
<a class="ilHide" href="<%= product.data["product.buy_homedepot"].value[0].text %>"><img class="homedepot" style="display:inline;position:relative;" src="images/homedepot.png" alt="Home Depot" /></a>
<a class="ilHide" href="<%= product.data["product.buy_walmart"].value[0].text %>"><img class="walmart" style="width:200px;" src="images/walmart.jpeg" alt="Walmart" /></a>
答案 0 :(得分:1)
我假设您希望在保留在当前页面的同时导航到新选项卡中的锚点href。如果它是正确的,您需要:
新的点击处理程序:
class ViewController: UIViewController {
var tapCount: Int = 0
var pulseSpeed: Double = 3
let pulseAnimLayer = CALayer()
let pulseAnim = CABasicAnimation(keyPath: "Opacity")
override func viewDidLoad() {
super.viewDidLoad()
counter.center = CGPoint(x: 185, y: 118)
pulseAnim.fromValue = 0.5
pulseAnim.toValue = 1.0
pulseAnim.duration = 3.0
pulseAnim.autoreverses = true
pulseAnim.repeatCount = .greatestFiniteMagnitude
pulseAnimLayer.add(pulseAnim, forKey: "Opacity")
}
func pulseAnimation(pulseSpeed: Double) {
UIView.animate(withDuration: pulseSpeed, delay: 0,
options: [UIViewAnimationOptions.repeat, UIViewAnimationOptions.autoreverse],
animations: {
self.red.alpha = 0.5
self.red.alpha = 1.0
}
)
}
@IBOutlet weak var red: UIImageView!
@IBOutlet weak var counter: UILabel!
@IBAction func screenTapButton(_ sender: UIButton) {
tapCount += 1
counter.text = "\(tapCount)"
pulseSpeed = Double(3) / Double(tapCount)
pulseAnim.duration = pulseSpeed
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}