gpt4 book ai didi

javascript - 如何分享弹窗的url?

转载 作者:行者123 更新时间:2023-12-01 01:41:18 26 4
gpt4 key购买 nike

我找到了一个将 xml 数据加载到弹出框的代码。我尝试分享弹出框的 URL。但代码不支持分享URL。当尝试在新选项卡中打开弹出窗口的 URL 时,需要直接显示弹出窗口。我怎样才能实现代码?

这是我找到的代码。

      $(document).ready(function(){
$.ajax({
type:"GET",
url:"data.xml",
dataType:"xml",
success:xmlParser
});
});

function xmlParser(xml){
xml = $(xml).children();
let total = $(xml).children().length;
$(xml).children().each(function (idx) {

let tag = $(this).prop("tagName");
let nextIdx = idx + 1;
let prevIdx = idx - 1;
//to make cyclic
nextIdx = nextIdx == total ? 0 : nextIdx;
prevIdx = prevIdx == -1 ? (total -1) : prevIdx;

let image = '<img style="background-image:url(' + $(this).find("image").text() + ')"' + '" />';
let image2 = '<div><img src="' + $(this).find("image").text() + '" width="100%" alt="' + '" />' + '</div>';
let head = '<div>' + $(this).find("head").text() + '</div>';


let html = `<div class="col-sm-4 random" id="random">
<div class="thumbnail randomdiv3" id="border" >
<a href="#${tag + idx}" id="openModalBtn">
<div>${image}</div>
<h5>${head}</h5>
</a>
</div>
</div>`;
let popup = `<div id="${tag + idx}" class="overlay">
<div class="popup">

<a href="#${tag + prevIdx}" class="previous round">&#8249;</a>
<a href="#${tag + nextIdx}" class="next round">&#8250;</a>
<h6>${head}</h6>
<a class="close" href="#">&times;</a>
<div>${image2}</div>
</div>
</div>`;


$("#xmldata").append(html);
$("#popup").append(popup);
});
}
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 30%;
position: relative;
transition: all 2s ease-in-out;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
.popup .content {
max-height: 30%;
overflow: auto;
}
.thumbnail img {
width: 100%;
height: 272px;
background-size: cover;
background-repeat: no-repeat;
background-position: 50% 20%;
vertical-align: middle;
position: inherit;
}

.previous {
background-color: #000;
color: white;
padding: 8px 16px;
}

.next {
background-color: #000;
color: white;
padding: 8px 16px;
}

.round {
border-radius: 50%;
}
<div class="row" id="xmldata"></div>

<div id="popup"></div>

http://next.plnkr.co/edit/70HUWx64QlKhfMIh?open=lib%2Fscript.js

最佳答案

您可以使用 url hash 来共享弹出 url

我已经更新了您的code请检查一下并告诉我,每次您单击链接打开弹出窗口时,它都会更新您的窗口哈希,您可以将该网址分享给任何将直接打开图像弹出窗口的人

关于javascript - 如何分享弹窗的url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52399242/

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