gpt4 book ai didi

javascript - 如何使我的对象重定向整个页面而不仅仅是它本身

转载 作者:行者123 更新时间:2023-11-30 13:55:10 24 4
gpt4 key购买 nike

我的标签中有一个 SVG。当我点击它时,我想重定向页面。

<object class="SVGClass centered" data="/Data/Blue_Force.svg" type="image/svg+xml" id="BF1SVG"style="margin:20px"></object>
<script>
var SVG1 = document.getElementById("BF1SVG");
var SVGElements1;
var SVGLoaded1 = false;
if(!SVGLoaded){
SVG1.addEventListener('load',function(){
SVGLoaded1 = true;
SVGElements1 = SVG1.contentDocument;

SVGElements1.getElementById("svgCC").setAttributeNS(null, "onclick", "window.location.href='http://686amppi5.campus.nist.gov/cryoConceptsStateViewer.html'");
});
</script>

svgCC 是外部 SVG 的 id。当我点击它时,对象本身变成了新页面,就像一个嵌入式窗口,而不是重定向浏览器。

我也试过:

document.getElementById("BF1SVG").setAttribute("onclick", "window.location.href='http://686amppi5.campus.nist.gov/cryoConceptsStateViewer.html'");

但这什么也做不了。我的 svg 不可点击。

最佳答案

你不应该那样设置 onclick 属性......试试这个。

document.getElementById("BF1SVG").addEventListener(
'click',
() => window.location.assign('http://686amppi5.campus.nist.gov/cryoConceptsStateViewer.html');
);

关于javascript - 如何使我的对象重定向整个页面而不仅仅是它本身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57436594/

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