admin管理员组文章数量:1133946
I have a link like this:
<a href="/index2.php?option=com_jumi&fileid=3&Itemid=11" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,')
I want the new opening window to open in a specific size. How do I specify the height and width?
I have a link like this:
<a href="/index2.php?option=com_jumi&fileid=3&Itemid=11" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,')
I want the new opening window to open in a specific size. How do I specify the height and width?
Share Improve this question edited Jul 1, 2014 at 7:43 Muhammad Kamran 5611 gold badge7 silver badges19 bronze badges asked Jan 28, 2010 at 19:09 Alex GordonAlex Gordon 60.6k302 gold badges702 silver badges1.1k bronze badges 1- Does this answer your question? Open URL in new window with JavaScript – halt9k Commented May 29, 2024 at 23:10
9 Answers
Reset to default 215<a href="/index2.php?option=com_jumi&fileid=3&Itemid=11"
onclick="window.open(this.href,'targetWindow',
`toolbar=no,
location=no,
status=no,
menubar=no,
scrollbars=yes,
resizable=yes,
width=SomeSize,
height=SomeSize`);
return false;">Popup link</a>
Where width and height are pixels without units (width=400 not width=400px).
In most browsers it will not work if it is not written without line breaks, once the variables are setup have everything in one line:
<a href="/index2.php?option=com_jumi&fileid=3&Itemid=11" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=SomeSize,height=SomeSize'); return false;">Popup link</a>
window.open ("http://www.javascript-coder.com",
"mywindow","menubar=1,resizable=1,width=350,height=250");
from
http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
:]
window.open('http://somelocation.com','mywin','width=500,height=500');
Just add them to the parameter string.
window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=250')
<a style="cursor:pointer"
onclick=" window.open('http://YOUR.URL.TARGET','',' scrollbars=yes,menubar=no,width=500, resizable=yes,toolbar=no,location=no,status=no')">Your text</a>
These are the best practices from Mozilla Developer Network's window.open page :
<script type="text/javascript">
var windowObjectReference = null; // global variable
function openFFPromotionPopup() {
if(windowObjectReference == null || windowObjectReference.closed)
/* if the pointer to the window object in memory does not exist
or if such pointer exists but the window was closed */
{
windowObjectReference = window.open("http://www.spreadfirefox.com/",
"PromoteFirefoxWindowName", "resizable,scrollbars,status");
/* then create it. The new window will be created and
will be brought on top of any other window. */
}
else
{
windowObjectReference.focus();
/* else the window reference must exist and the window
is not closed; therefore, we can bring it back on top of any other
window with the focus() method. There would be no need to re-create
the window or to reload the referenced resource. */
};
}
</script>
<p><a
href="http://www.spreadfirefox.com/"
target="PromoteFirefoxWindowName"
onclick="openFFPromotionPopup(); return false;"
title="This link will create a new window or will re-use an already opened one"
>Promote Firefox adoption</a></p>
Anyone looking for a quick Vue file component, here you go:
// WindowUrl.vue
<template>
<a :href="url" :class="classes" @click="open">
<slot></slot>
</a>
</template>
<script>
export default {
props: {
url: String,
width: String,
height: String,
classes: String,
},
methods: {
open(e) {
// Prevent the link from opening on the parent page.
e.preventDefault();
window.open(
this.url,
'targetWindow',
`toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=${this.width},height=${this.height}`
);
}
}
}
</script>
Usage:
<window-url url="/print/shipping" class="btn btn-primary" height="250" width="250">
Print Shipping Label
</window-url>
Using function in typescript
openWindow(){
//you may choose to deduct some value from current screen size
let height = window.screen.availHeight-100;
let width = window.screen.availWidth-150;
window.open("http://your_url",`width=${width},height=${height}`);
}
Using a button to refer to another window with a single click
<Button onClick={() => {window.open("https://www.google.com")}}>
Button Description
</Button>
本文标签: javascriptonclick open window and specific sizeStack Overflow
版权声明:本文标题:javascript - onclick open window and specific size - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736789492a1953025.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论