यह (जावास्क्रिप्ट का उपयोग करके) संभव नहीं है की तरह काम कर रहा है। आधुनिक ब्राउज़रों में उपयोगकर्ता द्वारा शुरू की गई प्रिंट घटनाओं के लिए कुछ प्रयोगात्मक समर्थन हैं, लेकिन are not cancelable ("सरल घटनाएं") ताकि संपूर्ण पृष्ठ अभी भी प्रिंट हो जाएगा भले ही आप ब्याज के फ्रेम को मुद्रित करने के लिए कस्टम कोड इंटरैक्ट करते हैं।
इस सीमा को देखते हुए, आपकी सबसे अच्छी शर्त शायद उपयोगकर्ताओं को एक बड़ा बटन प्रदान करने के लिए है जो आपके कस्टम फ्रेम प्रिंटिंग फ़ंक्शन को फायर करता है (printContentFrameOnly
नीचे देखें, तर्क के बिना इसे आग लगें) और उम्मीद है कि वे ctrl-p के बजाय बटन का उपयोग करेंगे ।
यदि यह संभव होगा, इस तरह से यह करने के लिए (this answer के आधार पर) होगा:
// listener is a function, optionally accepting an event and
// a function that prints the entire page
addPrintEventListener = function (listener) {
// IE 5.5+ support and HTML5 standard
if ("onbeforeprint" in window) {
window.addEventListener('beforeprint', listener);
}
// Chrome 9+, Firefox 6+, IE 10+, Opera 12.1+, Safari 5.1+
else if (window.matchMedia) {
var mqList = window.matchMedia("print");
mqList.addListener(function (mql) {
if (mql.matches) listener(); // no standard event anyway
});
}
// Your fallback method, only working for JS initiated printing
// (but the easiest case because there is no need to cancel)
else {
(function (oldPrint) {
window.print = function() {
listener(undefined, oldPrint);
}
})(window.print);
}
}
printContentFrameOnly = function (event) {
if (event) event.preventDefault(); // not going to work
window.frames['webcontent'].focus();
window.frames['webcontent'].print();
}
addPrintEventListener(printContentFrameOnly);
मैं जावास्क्रिप्ट समाधान की तलाश में था, क्योंकि सीएसएस ने मेरे लिए काम नहीं किया था। इसे एक उत्तर के रूप में चिह्नित करना। – Burjua
धन्यवाद। इसके लायक होने के लिए, मैं पूरी तरह से सहमत हूं कि एक्सडीएनपी ने बक्षीस पुरस्कार के लायक हैं, और मैंने उनका जवाब भी उठाया। – Julian