this is my jquery code:
jQuery('.print_btn').hide();
var contents = document.getElementById("print_page").innerHTML;
var frame1 = document.createElement('iframe');
frame1.name = "frame1";
frame1.style.position = "absolute";
frame1.style.top = "-1000000px";
document.body.appendChild(frame1);
var frameDoc = (frame1.contentWindow) ? frame1.contentWindow : (frame1.contentDocument.document) ? frame1.contentDocument.document : frame1.contentDocument;
frameDoc.document.open();
frameDoc.document.write('<html><head><title></title>');
frameDoc.document.write('</head><body>');
frameDoc.document.write(contents);
frameDoc.document.write('</body></html>');
frameDoc.document.close();
setTimeout(function () {
frameDoc.focus();
frameDoc.print();
document.body.removeChild(frame1);
}, 500);
jQuery('.print_btn').show();
return false;
I search on google but i did not find any solution so i am posting this question.
I have a pop which is having image and a print button , i want to print the image on click on print button.
This working fine on web browser means on desktop, But it is printing whole page and pop-up image , and on i pad it is printing nothing .
Why this is happening i don't know please help me out.
Unfortunately .print() isn't supported on Android devices. You could however use Googles cloud print API: https://developers.google.com/cloud-print/docs/gadget
Related
I’ve got a piece of JavaScript code that prints the content located inside a specific div( #printthis ). It works great on PC; however, when I try to use it on an ipad, the page is blank except for the “footer” that contains the page name, date, time, and how many pages. The footer is set via the print driver/iPad.
Any way to modify this code to work on both PC and ipad? I haven’t tested on any other devices yet. These are just the devices I use regularly.
<script type="text/javascript">
function printdata(title) {
var thistitle = title;
var contents = $("#printthis").html();
var frame1 = $('<iframe />');
frame1[0].name = "frame1";
frame1.css({ "position": "absolute", "top": "-1000000px" });
$("body").append(frame1);
var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
frameDoc.document.open();
//Create a new HTML document.
frameDoc.document.write('<html><head><title><?php if(isset($title)) { echo strtoupper($title) .' '; } ?>LIST PRICE</title>');
frameDoc.document.write('</head><body>');
//Append the external CSS file.
frameDoc.document.write('<link href="style.css" rel="stylesheet" type="text/css" />');
//Append the DIV contents.
frameDoc.document.write(contents);
frameDoc.document.write('</body></html>');
frameDoc.document.close();
setTimeout(function () {
window.frames["frame1"].focus();
window.frames["frame1"].print();
frame1.remove();
}, 500);
}
</script>
I call this function via <a onclick="printdata()" href="javascript:void(0)">Print</a>
I'm trying to deeplink into an app from the browser, that's working fine.
But the problem is, that iOS is showing a "Safari can't open the page" and then redirects to the app store (fallback solution).
Is it possible to make some JS magic, so that popup box doesn't appear?
Here is the code:
var now = new Date().valueOf();
setTimeout(function () {
if (new Date().valueOf() - now > 100) return;
window.location = "https://itunes.apple.com/us/app/twitter/id333903271?mt=8";
}, 10);
window.location = "twitter://timeline";
I encountered a similar scenario some time back and I figured the best way to go about is have an iframe and provide a source to it..
function mobileDeepLink() {
var iframe = document.createElement('iframe');
iframe.src = "twitter://timeline";
// hide iframe visually
iframe.width = 0;
iframe.height = 0;
iframe.frameBorder = 0;
var now = new Date().valueOf();
setTimeout(function () {
if (new Date().valueOf() - now > 100) return;
window.location = "https://itunes.apple.com/us/app/twitter/id333903271?mt=8";
}, 10);
// Append it to the body.
document.body.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
}
mobileDeepLink();
That way you would not see the error popup when the scheme cannot be found.
Update
This approach will only work for IOS 8 and lower. From IOS 9 and later, deep linking is being supported natively using universal links.
I created a simple bookmarklet to append 3 invisible iframe's to the current document looking like this:
javascript: (function() {
var link = window.location.href;
var desktop = link.replace(".com", ".com/purge");;
var mobile = link.replace(".com", ".com/mpurge");
var tablet = link.replace(".com", ".com/tpurge");
var platforms = [desktop,tablet,mobile];
for (i = 0;i<platforms.length; i++){
ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", platforms[i]);
ifrm.style.width = 0+"px";
ifrm.style.height = 0+"px";
document.body.appendChild(ifrm);
if(i==platforms.length-1){
ifrm.onload = function(){
location.reload();
}
}
}
})();
what i want to do its to refresh the page im at after the third iframe is loaded but for some reason i cant get this one to work, any idea why?
thx!
i will never be == platforms.length inside of loop, because your loop condition is i<platforms.length.
Make it i == platforms.length - 1 or take reloading outside of the loop
I have read up on all issues regarding Safari and blank printing. It seems that a white flash happens, re-rendering the page, and content of the iframe is lost before a print dialog can grab it.
Here is my javascript - It works in all browsers except safari. It brings up the dialog, but prints a blank page.
function PrintPopupCode(id) {
framedoc = document;
var popupFrame = $(framedoc).find("#" + id + '\\!PopupFrame');
var icontentWindow = popupFrame[0].contentWindow || popupFrame[0].contentDocument;
icontentWindow.focus();
icontentWindow.print();
}
function PrintPopup(id) {
setTimeout(function () { PrintPopupCode(id) }, 3000);
}
I have set a timeout, i previously read it would help if the transfer of content took sometime, but it has not helped.
I have also tried with printElement() function on the icontentWindow variable, but it does not support this method.
Print Element Method
This is all in a .js file, and not on the page. I have tried on the page, but the same thing happens.
Help?
Maybe you should try this:
function PrintPopupCode(id) {
framedoc = document;
var popupFrame = $(framedoc).find("#" + id + '\\!PopupFrame');
var icontentWindow = popupFrame[0].contentWindow || popupFrame[0].contentDocument;
icontentWindow.focus();
setTimeout(icontentWindow.print, 3000);
}
function PrintPopup(id) {
PrintPopupCode(id);
}
I have a javascript widget which fetches articles from Wikipedia through MediaWiki API (http://en.wikipedia.org/w/index.php?title=Main_Page&action=render). It's an app for Samsung Smart TVs. Now the text part works fine, but it won't display any images because the img src is structured like this:
"//en.wikipedia.org/wiki/File:example.jpg"
and I've come to realize by using a PC emulator that the Samsung firmware converts it to this type of full url:
"file://localhost/en.wikipedia.org/wiki/File:example.jpg"
Is it possible to add "http:" to the src so that the app points to the correct links hence displaying both thumbnails and full-size images?
Here's the relevant part of the js code:
UIContents.showImage = function(srcURLFromWikiPage, showHigherResolution) {
// alert("UIContents.fillDescription()");
var cutURL = srcURLFromWikiPage;
//document.getElementById('UIContentsImgFrameiFrame').href = srcURL;
//window.frames.UIContentsImgFrameiFrame.location.href = srcURL + "#file";
//prepare link for full-size picture:
//cutURL = cutURL.replace('thumb/','');
//cutURL = cutURL.substring(0, cutURL.lastIndexOf('/'));
//show preview thumb version
//if (cutURL.match(/\.svg$/)) cutURL = srcURLFromWikiPage;
alert('img src: ' + cutURL);
//show preview thumb version
var elemImg = document.getElementById('UIContentsImgFrameImage');
document.getElementById('UIContentsImgFrame').style.display = 'block';
//set image source
if (showHigherResolution == true) elemImg.onload = 'UIContents.resizeImage()';
elemImg.alt = 'loading...';
elemImg.src = cutURL;
elemImg.style.visibility = 'hidden';
elemImg.style.visibility = 'visible';
imageViewIsOpened = true;
document.getElementById('UISearchField').style.visibility = 'hidden';
document.getElementById('UISearchTextInput').style.visibility = 'hidden';
Any suggestions? Thanks in advance.
var cutURL = srcURLFromWikiPage.replace("file://localhost/","http://");