window.open 相关问题

它是一种JavaScript方法,它打开一个新窗口并加载给定URL指定的文档。

将 2D javascript 数组导出到 Excel 工作表

我知道,这里有数百个关于这个主题的问题,但经过一天的搜索,我仍然找不到满意的答案: 我有一个 2D javascript 数组,我想将其下载为

回答 3 投票 0

Safari 上与 window.open() 相关的问题

我知道 Safari 会在 ajax 调用期间尝试通过 window.open() 阻止打开新选项卡。 我们需要在ajax调用之前调用window.open()来打开一个新选项卡,这样程序就可以防止

回答 2 投票 0

window.open 由于活动文件选择器 Chome 更新而被阻止

我在react中尝试以下代码,并且在Chrome(更新)和Opera浏览器中收到以下错误。知道如何解决吗? 返回 ( 我在 React 中尝试以下代码,在 Chrome(更新)和 Opera 浏览器中收到以下错误。知道如何解决吗? return ( <Button component="label" role={undefined} variant="contained" tabIndex={-1} startIcon={<CloudUploadIcon />} > Upload file <VisuallyHiddenInput type="file" onChange={handleFileUpload} /> </Button> ); const handleFileUpload = (e) => { if (!e.target.files) { return; } const file = e.target.files[0]; const filename = file.name; window.open( import.meta.env.VITE_DAEJAVIEWER + `?image="${filename}"`, // a simply url "_blank" ); }; const VisuallyHiddenInput = styled("input")({ clip: "rect(0 0 0 0)", clipPath: "inset(50%)", height: 1, overflow: "hidden", position: "absolute", bottom: 0, left: 0, whiteSpace: "nowrap", width: 1, }) 错误: 另请注意,Firefox 可以正常工作,但在 Chrome、Opera、Edge 中则不行 谢谢 这是因为您引用的是当前文件。您需要将其转换为另一个 blob,以便它引用活动文件之外的另一个文件。您可以在这里尝试一下。 function base64toBlob(base64Data, contentType) { contentType = contentType || ""; const sliceSize = 1024; const byteCharacters = atob(base64Data); const byteArrays = []; for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) { const slice = byteCharacters.slice(offset, offset + sliceSize); const byteNumbers = new Array(slice.length); for (let i = 0; i < slice.length; i++) { byteNumbers[i] = slice.charCodeAt(i); } const byteArray = new Uint8Array(byteNumbers); byteArrays.push(byteArray); } return new Blob(byteArrays, { type: contentType }); } const handleTab = (url) => { const newTab = window.open(`${url}`, "_blank"); if (newTab) { newTab.addEventListener("unload", () => { URL.revokeObjectURL(url); }); } else { console.log("error", "haha"); } }; const handleFiles = (file) => { const fr = new FileReader(); fr.onload = function () { console.log(fr.result); const blob = base64toBlob( fr.result.replace("data:application/pdf;base64,", ""), file.type ); const url = URL.createObjectURL(blob); handleTab(url); }; fr.readAsDataURL(file); }; const fielInput = document.querySelector("#file"); fielInput.addEventListener("change", (e) => { if (!e.target.files[0]) return; handlePDF(e.target.files[0]); });

回答 1 投票 0

javascript 在外部程序而不是浏览器中打开链接

有什么方法可以使用javascript在外部程序中打开链接而不是(!)在网络浏览器中打开链接? 背景:从 CRM2015 本地部署,我想在 Lotus Notes 中打开邮件。 脚本: 有没有办法使用 javascript 在外部程序中打开链接,而不是(!)在网络浏览器中打开链接? 背景:从 CRM2015 本地部署我想在 Lotus Notes 中打开邮件。 脚本: <html> <body> <p onclick="myFunction()">Click me</p> <script> function myFunction() { window.open("notes:///server/file"); } </script> </body> </html> 发生了什么:邮件在 Lotus Notes 中打开 -> 良好 但 IE11 中还会出现一个附加选项卡,地址栏中的空白页面和链接 -> 错误 应该发生什么:邮件将在 Lotus Notes 中打开,但在 IE11 中没有其他选项卡或窗口。 有什么办法可以解决我的问题吗? 非常感谢您的帮助,祝周末愉快! 如果您想通过 JS 导航到外部协议,请按照导航到 HTTP URL 的方式进行操作: function goSomewhere() { window.location = "notes:///server/file"; } 正常的浏览器应该 1. 停留在同一页面,并且 2. 启动外部程序(强调 应该,对于疯狂的浏览器不做任何保证 - 例如 IE8 及以下版本)。 你好,这篇文章很旧,但我尝试使用 macOS-Sonoma (M3) 和 safari 版本 17.3.1 function goSomewhere() { window.location = "notes:///server/file"; } 它工作正常,但我有 2 个问题 首先:我不明白 ///server/file 这不是 Notes 的真实路径? 第二:如果我对此脚本感兴趣,那是因为我想启动(在客户端上)VLC 应用程序(或其他)这可能吗? 我注意到启动笔记、消息、照片都可以 但是日历、电子邮件...并且不知道为什么? 谢谢

回答 2 投票 0

根据变量打开窗口

上一页 下一个 <html> <body> <button onclick="previous()">previous</button> <button onclick="next()">next</button> <img src="https://th.bing.com/th/id/OIP.-d3JKGX5ZJ3Y3U7ybY8h8gHaE7?rs=1&pid=ImgDetMain" onclick="reDirect()"></img> <script> maxnum=4 num=0 function previous(){ if(num>0) { num++ } else{} } function next(){ if(num<maxnum){ num++ } else{} } function reDirect(){ if(num=0) { window.open("https://youtube.com"); } else{} } </script> </body> </html> 我想要一个函数来检查变量并根据变量重定向到另一个页面。 这是需要的,因为我想要制作的整个脚本的图像也会根据变量而变化,如果没有制作图像的页面,该功能将毫无用处,所以我也希望它具有选择性。 评论是对的,是==0问题。

回答 1 投票 0

Javascript:遍历 URL 数组并打开,然后按定义的时间间隔关闭

我有一个 URL 数组,需要循环遍历并在新窗口中打开。但是,我需要能够在每个窗口的打开和关闭之间设置超时。换句话说,窗户应该...

回答 1 投票 0

从不同选项卡页面单击时,具有相同目标的弹出链接会在不同窗口中打开

我有一个名为 home.html 的 html 页面。 在该页面上我有一个打开弹出窗口的链接,html代码如下:

回答 0 投票 0

无法使用javascript访问window.open html id

无法访问window.open中的ID。窗口显示,内容就在那里,但 var table-modal 返回 null。在浏览器中思考javascript,有一个window.if...

回答 2 投票 0

如何传递选项参数的 JSON 对象来打开新窗口?

window.open() 对象有一些时髦的参数列表...... 有没有办法做类似 window.open({options..}); 的事情 想法?

回答 8 投票 0

window.open 在 chrome 中直到父窗口执行完成后才会加载新窗口内容

我是javascript新手,面临着window.open在chrome中父窗口执行完成之前不加载新窗口内容的问题。 例如 :- 函数 abc(){ 几行

回答 1 投票 0

如何检查使用 window.open() 打开的选项卡是否仍在运行、关闭或刷新?

const newWindow = window.open( "", “_空白的”, “宽度=800,高度=600,左=2000,顶部=0” ); 如果(新窗口){ const SpecificDivContent = doc...

回答 1 投票 0

获取 if/else 语句的元素 ID

正在做一个项目。我需要 else 语句才能工作,但是当我点击提交按钮时,它只是重定向到“if” var 判断量 = document.getElementById('</desc> <question vote="0"> <p>正在从事一个项目。我需要 else 语句才能工作,但是当我点击提交按钮时,它只是重定向到“if”</p> <pre><code>&lt;head&gt; &lt;script&gt; var judgmentAmount = document.getElementById(&#39;judgmentAmount&#39;); var amountCollected = document.getElementById(&#39;amountCollected&#39;); function judgmentCalc() { if( judgmentAmount - amountCollected &lt; 10000 ) { window.open( &#39;http://afjudgment.com&#39; ); }else { window.open( &#39;http://www.yahoo.com&#39; ); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Application&lt;/h1&gt; &lt;p&gt;I understand that this application neither obligates me to &lt;b&gt;Affirmative Judgment&lt;/b&gt; nor does it obligate &lt;b&gt;Affirmative Judgment&lt;/b&gt; to me.&lt;/p&gt; &lt;h3&gt;Judgment Information&lt;/h3&gt; &lt;form&gt; &lt;span&gt;Do you have a case number?&lt;/span&gt; &lt;input type=&#34;text&#34; name=&#34;caseNumber&#34; /&gt; &lt;span&gt;Amount of Judgment&lt;/span&gt; &lt;input type=&#34;text&#34; name=&#34;judgmentAmount&#34; id=&#34;judgmentAmount&#34; /&gt; &lt;span&gt;Amount collected to date&lt;/span&gt; &lt;input type=&#34;text&#34; name=&#34;amountCollected&#34; id=&#34;amountCollected&#34; /&gt; &lt;input type=&#34;submit&#34; name=&#34;submitButton&#34; onclick=&#34;judgmentCalc();&#34; /&gt; &lt;/form&gt; </code></pre> </question> <answer tick="false" vote="0"> <p>您需要访问这些输入字段的值,而不是直接处理 <pre><code>document.getElementById()</code></pre> 返回的 dom 元素。您可以使用 <pre><code>input</code></pre> 属性获取 <pre><code>.value</code></pre> 的值。</p> <pre><code>var judgmentAmount = document.getElementById(&#39;judgmentAmount&#39;).value; var amountCollected = document.getElementById(&#39;amountCollected&#39;).value; </code></pre> </answer> <answer tick="false" vote="0"> <p>将变量移到函数内部,以便在函数执行时正确填充它们,并添加 DOM 元素的 .value 属性。</p> <p>试试这个:</p> <pre><code> function judgmentCalc() { var judgmentAmount = document.getElementById(&#39;judgmentAmount&#39;).value; var amountCollected = document.getElementById(&#39;amountCollected&#39;).value; if( judgmentAmount - amountCollected &lt; 10000 ) { window.open( &#39;http://afjudgment.com&#39; ); }else { window.open( &#39;http://www.yahoo.com&#39; ); } } </code></pre> </answer> <answer tick="false" vote="0"> <p>您只是比较对象,您需要比较它们的值</p> <pre><code>var judgmentAmount = Number(document.getElementById(&#39;judgmentAmount&#39;).value); var amountCollected = Number(document.getElementById(&#39;amountCollected&#39;).value); </code></pre> <p>另外,在比较之前将它们转换为数字。</p> <pre><code>function judgmentCalc() { var judgmentAmount = Number(document.getElementById(&#39;judgmentAmount&#39;).value); var amountCollected = Number(document.getElementById(&#39;amountCollected&#39;).value); if( judgmentAmount - amountCollected &lt; 10000 ) { window.open( &#39;http://afjudgment.com&#39; ); }else { window.open( &#39;http://www.yahoo.com&#39; ); } } </code></pre> </answer> <answer tick="false" vote="0"> <p>您将在此处获取 HTML DOM 元素:</p> <pre><code>var judgmentAmount = document.getElementById(&#39;judgmentAmount&#39;); var amountCollected = document.getElementById(&#39;amountCollected&#39;); </code></pre> <p>因此,在您的 <pre><code>judgementCalc</code></pre> 方法中,您需要获取这些元素的值:</p> <pre><code>function judgmentCalc() { // notice that we&#39;re using VALUE here: if( judgmentAmount.value - amountCollected.value &lt; 10000 ) { window.open( &#39;http://afjudgment.com&#39; ); }else { window.open( &#39;http://www.yahoo.com&#39; ); } } </code></pre> </answer> <answer tick="false" vote="0"> <p>您需要根据元素的值进行操作:</p> <pre><code>function judgmentCalc() { var judgmentAmount = +document.getElementById(&#39;judgmentAmount&#39;).value; var amountCollected = +document.getElementById(&#39;amountCollected&#39;).value; if( judgmentAmount - amountCollected &lt; 10000 ) { window.open( &#39;http://afjudgment.com&#39; ); } else { window.open( &#39;http://www.yahoo.com&#39; ); } } </code></pre> <p>var <pre><code>judgmentAmount = document.getElementById(&#39;judgmentAmount&#39;)</code></pre> 仅返回对 ID 为“judgmentAmount”的元素的引用。如果你想使用元素的值,你需要这样做:</p> <p><pre><code>var judgmentAmount = document.getElementById(&#39;judgmentAmount&#39;).value</code></pre>。 </p> <p>下一步是计算一些金额。您需要将 string 转换为 int (使用 <pre><code>+</code></pre> 运算符)</p> <pre><code>typeof judgmentAmount; // &#34;string&#34; typeof +judgmentAmount; // &#34;number&#34; </code></pre> <p><a href="https://jsfiddle.net/ova74kmh/" rel="nofollow">演示</a></p> </answer> <answer tick="false" vote="-1"> <p>请运行下面的脚本,它会正常工作:</p> <pre><code>&lt;head&gt; &lt;script&gt; function judgmentCalc() { var judgmentAmount = document.getElementById(&#39;judgmentAmount&#39;).value; var amountCollected = document.getElementById(&#39;amountCollected&#39;).value; var exp = parseFloat(judgmentAmount) - parseFloat(amountCollected); if( exp &lt; 10000 ) { window.open( &#39;http://afjudgment.com&#39; ); } else { window.open( &#39;http://www.yahoo.com&#39; ); } } &lt;/script&gt; &lt;/head&gt; </code></pre> </answer> <answer tick="false" vote="-1"> <p>您必须比较输入元素的值,请尝试以下操作</p> <pre><code>function judgmentCalc() { var judgmentAmount = document.getElementById(&#39;judgmentAmount&#39;).value; var amountCollected = document.getElementById(&#39;amountCollected&#39;).value; if( (judgmentAmount - amountCollected) &lt; 10000 ) { window.open( &#39;http://afjudgment.com&#39; ); } else { window.open( &#39;http://www.yahoo.com&#39; ); } } </code></pre> <p>它可能对你有帮助。</p> </answer> </body></html>

回答 0 投票 0

如何在 Chrome、Angular 14 上使用 window.open() 但仍关注原始窗口?

我想遍历数组并在新的 Chrome 选项卡中使用其链接打开其元素。但是,我不希望它专注于新选项卡。只需关注原始窗口即可。 有谁知道吗...

回答 1 投票 0

如何避免打开新选项卡时出现空白被阻塞

我正在使用下面的代码在新窗口中打开页面,它按预期工作,但是当我右键单击“在新选项卡中打开”时,它会被“about:blank#blocked”阻止,我预计...

回答 3 投票 0

在新选项卡中将表单输入添加到 URL

我目前正在使用下面的方法将用户的输入添加到 URL,但它会在同一窗口中打开。我尝试过 window.open 来获取在新选项卡中打开的链接,但没有成功。我也尝试过添加 _blank...

回答 1 投票 0


页面重新加载后保存/传递/获取事件

我尝试使用自定义网址方案打开科尔多瓦应用程序。 当我在触发事件后使用它时,它工作正常,如下所示: 福...

回答 2 投票 0

在 Delphi 中通过 Android WebView 使用 Window.open 脚本打开弹出窗口

使用 android webview 时不会创建弹出窗口 Android WebKit 默认不支持,所以在 Android Studio 中 有覆盖支持的使用示例,因此很容易...

回答 0 投票 0

Opening a computed document using window.open() and data: scheme

我有一个在浏览器中运行的网页,它生成一个计算出的 HTML 文档,我想在新的浏览器选项卡中打开该文档。 简单而肮脏的方法是这样做: const w = window.ope...

回答 1 投票 0

JavaScript window.open 有时会返回 null

我正在尝试维护一个我没有编写的系统(我们不是所有人吗?)。它是用 C Sharp 和 JavaScript 编写的,带有 Telerik 报告。 它在 JavaScript 中包含以下代码......

回答 5 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.