खुली खिड़की और विशिष्ट आकार पर क्लिक करें


87

मेरा लिंक इस तरह है:

<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,')

मैं चाहता हूं कि नई ओपनिंग विंडो एक विशिष्ट आकार में खुले। मैं ऊंचाई और चौड़ाई कैसे निर्दिष्ट करूं?

जवाबों:


177
<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 नहीं चौड़ाई = 400px)।

अधिकांश ब्राउज़रों में यह काम नहीं करेगा यदि यह बिना लाइन ब्रेक के नहीं लिखा जाता है, एक बार चर सेट होने के बाद एक लाइन में सब कुछ होता है:

<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
आप अंतिम ")" वर्ण "के लिए भी स्वैप करना चाहेंगे); गलत लौटें;" पॉपअप के अतिरिक्त मूल लिंक को रोकने के लिए।
एंड्रयू

2
एक पुराना, लेकिन मैंने इसे खोज के माध्यम से पाया, इसलिए सही उत्तर के अनुसार @AndrewSpear
नील

1
@ लॉरी हिप्प मैं स्क्रीन के आकार को फिट करने के लिए इसे कैसे बदल सकता हूं?
इधम चौधरी

@IdhamChoudry बस चौड़ाई / ऊंचाई गुण हटा दें और यह स्वचालित रूप से सभी उपलब्ध स्थान ले लेगा। मेरा मानना ​​है कि सेटिंग width=100vw, height=100vhभी काम करेगी।
वडकोरक्वेस्ट

1
मेरे लिए यह काम करता है, लेकिन एक महत्वपूर्ण चीज - आपको अपने फ़ंक्शन के शरीर में लाइन ब्रेक का उपयोग नहीं करना चाहिए, जैसा कि ऊपर दिए गए उदाहरण में किया गया है। मैंने लाइन ब्रेक हटा दिए हैं और यह मेरे लिए काम कर रहा है।
यूजीन



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>

हालाँकि मैं पूछता हूँ, यह पहले से दिए गए सभी उत्तरों में क्या जोड़ता है?
EW24

3

ये मोज़िला डेवलपर नेटवर्क की विंडो से सबसे अच्छे अभ्यास हैं। पृष्ठ:

<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>
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.