提问人:Jack 提问时间:11/17/2023 最后编辑:Jack 更新时间:11/18/2023 访问量:24
如何触发 iframe 加载到新标签页中?
How to trigger the iframe to load in a new tab?
问:
我有一个加载 iFrame 的按钮。我想提供另一个按钮来打开并在新选项卡中加载 iFrame。 目前,我使用按钮打开基本上复制页面,但不确定如何触发框架的加载:
<button onclick="ViewFolder('f6f906a14')">Open cases below </button>
<a href="#" rel="noopener"><button>Open cases in a new tab</button></a>
<iframe id="postdicom-iframe" height="720" width="600"></iframe>
我试图研究一些 JS 以在新选项卡中加载 iframe。我发现该选项卡将在新选项卡上显示相同的页面内容。
任何建议将不胜感激。
非常感谢, 千斤顶
var _apiKey = "68975ca0-58da-4fd8-8974-7614565466c";
var _accountKey = "1e072fb6-7805-4f1a-87dd-b5464564f5f7";
var _userUuid = "ee7e0713-1863-4913-b7da-6454364754da6";
var _folderUuid = "b5fb6b1c-c7ff-43b4-acef-4543554745d0";
////Send view request to PDAPI server and open it.
function ViewFolder(_folderUuid) {
if (_accountKey && _apiKey) {
//Create a instance of PDCloudAPI object.
var _cloudApi = new pDCloudApi(_apiKey, _accountKey);
_cloudApi.Initialize(function (result) {
if (result.Success) {
console.log("API is initialized successfully.");
console.log(result)
_cloudApi.GetFolderViewUrl(_userUuid, _folderUuid, function (response) {
console.error(response)
if (response.Success) {
var url = response.Result;
var iframe = document.getElementById("pd-iframe");
iframe.src = url;
document.getElementById("iframe-container").style.display="block";
}
else {
console.error(response.Message)
}
})
}
else {
console.error("API initialize error.")
console.error(result)
}
});
}
else {
console.error("'_apiKey' or '_accountKey' are undefined.")
}
}
function HideIframe(){
document.getElementById("iframe-container").style.display="none";
}
function openInNewTab(url) {
window.open(url, '_blank').focus();
}
答:
0赞
Surya R Praveen
11/18/2023
#1
function openInNewTab(url) {
window.open(url, '_blank').focus();
}
// Or just
window.open(url, '_blank').focus();
<div onclick="openInNewTab('www.test.com');">Something To Click On</div>
评论
0赞
Jack
11/18/2023
谢谢。对不起,我真的是 Javascript 的新手。我已经插入了该函数。加载 iFrame 时,指向新选项卡的链接应如何显示?目前:<button onclick=“ViewFolder('f6f906a14')”>在 </button 下打开案例>
0赞
Surya R Praveen
11/20/2023
@Jack - 你能更新小提琴/演示吗?这将是非常有帮助的
评论
ViewFolder()
_cloudApi