onclick 열린 창 및 특정 크기


89

다음과 같은 링크가 있습니다.

<a href="/index2.php?option=com_jumi&amp;fileid=3&amp;Itemid=11" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,')

새 열기 창이 특정 크기로 열리기를 원합니다. 높이와 너비는 어떻게 지정합니까?

답변:


179
<a href="/index2.php?option=com_jumi&amp;fileid=3&amp;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>

너비와 높이는 단위가없는 픽셀입니다 (너비 = 400이 아니라 너비 = 400 픽셀).

대부분의 브라우저에서 줄 바꿈없이 작성되지 않으면 작동하지 않습니다. 일단 변수가 설정되면 모든 것이 한 줄에 있습니다.

<a href="/index2.php?option=com_jumi&amp;fileid=3&amp;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> 

14
또한 마지막 ")"문자를 "); return false;"로 바꾸고 싶을 것입니다. 팝업 외에도 원래 링크가 열리는 것을 방지합니다.
Andrew

2
오래되었지만 검색을 통해 @AndrewSpear의 답장에 따라 정답을 찾았습니다
neil

1
@Larry Hipp 화면 크기에 맞게 변경하려면 어떻게해야합니까?
Idham Choudry

@IdhamChoudry 너비 / 높이 속성을 제거하면 사용 가능한 모든 공간이 자동으로 사용됩니다. 나는 설정 width=100vw, height=100vh도 작동 할 것이라고 믿습니다 .
Vadorequest

1
나를 위해 그것은 작동하지만 한 가지 중요한 것은 위의 예에서와 같이 함수 본문에 줄 바꿈을 사용해서는 안됩니다. 나는 줄 바꿈을 제거했고 그것은 나를 위해 일했습니다.
유진


20
window.open('http://somelocation.com','mywin','width=500,height=500');

12

매개 변수 문자열에 추가하기 만하면됩니다.

window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=250')

11
<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>

내가 물어 보지만 이것은 이미 주어진 모든 답변에 무엇을 추가합니까?
EWit 2014 년

3

다음은 Mozilla 개발자 네트워크 window.open 페이지 모범 사례입니다 .

<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>

0

빠른 Vue 파일 구성 요소를 찾는 사람은 다음과 같습니다.

// 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>

용법:

<window-url url="/print/shipping" class="btn btn-primary" height="250" width="250">
    Print Shipping Label
</window-url>
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.