I have the below code to print the text that is loaded in fancybox. It works perfect in chrome and firefox. But in ie9 it opens a blank window and closes. Then nothing happends.
jQuery(function($) {
$('a.print').click(function() {
var print_button = '';
var print_page = window.open('', 'Print', 'width=600,scrollbars=yes, height=700');
var html = '<h2><?php print t("Term & Condition"); ?></h2> <br/>' + '<?php echo $body_content; ?>';
print_page.document.open();
print_page.document.write(html);
print_page.print();
print_page.close();
return false;
});
});
Change the following:
print_page.document.write(html);
print_page.print();
into:
print_page.document.write(html);
print_page.document.close();
print_page.focus();
print_page.print();
JSFiddle.
Try adding <meta http-equiv="X-UA-Compatible" content="IE8"/> at head section so that the page renders in IE8 mode and check if it helps.
Related
look ...
i have a server installed on a linux machine ( RHEL 7 + PHP ) . where i have a server called " Printer " acessible by : 192.168.0.48/Printer.
i have a page php at my server that create a file with some ZPL LANGUAGE inside on this location
' \Printer\documents\'
its possible to send the file that has been generated to the printers of side-client via " window.open() " ?
or for example , get the content of this file and insert of this function ?
<script type="text/javascript">
function printZpl(zpl) {
var printWindow = window.open();
printWindow.document.open('text/plain')
printWindow.document.write(zpl);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
</script>
You can pass string to encodeURIComponent() at function call and set string as .textContent of <pre> element at opened window to preserve new line characters for at print() call
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button id="print">Print file</button>
<script type="text/javascript">
function printZpl(zpl) {
var printWindow = window.open(`data:text/html,<!DOCTYPE html><html><body><pre>${zpl}</pre><script>print();<\/script></body></html>`);
printWindow.focus();
}
var zpl = `^XA
^FXTest ZPL
^FS
^FO50,100
^A0N,89
^FDHello ZPL
^FS
^XZ`;
document.getElementById("print")
.onclick = function() {
printZpl(encodeURIComponent(zpl))
};
</script>
</body>
</html>
plnkr http://plnkr.co/edit/TBx0tNP0WkDODAz71qzO?p=preview
I'm working with OpenTok, trying to publish an app where a person shows a room and some clients can see, in order to buy it or not.
When using the example code in my localhost (and also in Firefox and nasty iExplorer) everything works smooth, but when I do it in Chrome i get this error in my JS Console:
OT.Publisher.onStreamAvailableError Permission Denied
I dont remember never saying "no" to any pop up that asked me permition to share my cam, so is not like "Chrome will remember my last choise".
Any help?
This is the code that I'm executing:
<?php
//Obviously I changed this.
$apiKey = "123456789";
$apiSecret = "VICTORIA's SECRET";
require '../vendor/autoload.php';
use OpenTok\OpenTok;
use OpenTok\MediaMode;
use OpenTok\Session;
use OpenTok\Role;
$opentok = new OpenTok($apiKey,$apiSecret);
$session = $opentok->createSession();
$sessionId = $session->getSessionId();
$data = array(
'role' => Role::PUBLISHER,
'data' =>""
);
$token = $session->generateToken($data);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>OpenTok Hello World</title>
<script src='https://static.opentok.com/v2/js/opentok.min.js'></script>
<!--script src="//static.opentok.com/webrtc/v2.2/js/TB.min.js"></script-->
<script type="text/javascript">
var token = '<?php echo $token; ?>';
var apiKey = '<?php echo $apiKey; ?>';
var sessionId = '<?php echo $sessionId; ?>';
var session = TB.initSession(sessionId);
var publisher = TB.initPublisher(apiKey, 'subscribers');
// Attach event handlers
session.on({
sessionConnected: function(event)
{
session.publish(publisher);
},
streamCreated: function(event)
{
var subContainer = document.createElement('div');
subContainer.id = 'stream-' + event.stream.streamId;
document.getElementById('subscribers').appendChild(subContainer);
session.subscribe(event.stream, subContainer);
}
});
session.connect(apiKey, token);
</script>
</head>
<body>
<h2>Hello, Universe!</h2>
<div id="publisher"></div>
<div id="subscribers"></div>
</body>
</html>
When I check the JS Console, I get this warning:
getUserMedia() no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.
An also this Error:
OT.Publisher.onStreamAvailableError Permission Denied
This is our development server, so is not https.
EDIT:
After checking the OpenTok JS that I have to load at the beging, I realice this:
// The user has clicked the 'deny' button the the allow access dialog
// (or it's set to always deny)
var onAccessDenied = function(error) {
if (_isScreenSharing) {
if (global.location.protocol !== 'https:') {
/**
* in http:// the browser will deny permission without asking the
* user. There is also no way to tell if it was denied by the
* user, or prevented from the browser.
*/
error.message += ' Note: https:// is required for screen sharing.';
}
}
logging.error('OT.Publisher.onStreamAvailableError Permission Denied');
So, It won't ask me if I'm using http. There's a way to workaround this? Overwrite this behavior?
I have attempted to go about the use of Paypal Lightbox a bit differently.
I have used a button to trigger an ajax call which then generates the PayKey and if all goes well then triggers the form (from the documentation) to be created and submitted.
When i click the button the lightbox html is created but the content is not loaded into it. Instead i get the error:
Load denied by X-Frame-Options: https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_dispatch-failed does not permit cross-origin framing.
My Code:
<head>
<script src="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>
</head>
External Script:
$("#checkout").click(function() {
var id = $(this).data("id");
if(id) { pay(id); }
});
function pay(id) {
$.ajax({
url : 'paypal/Pay-Chained.php',
type : 'POST',
data : "id="+id,
success : function (data) {
var info = (JSON.parse(data));
if (info['Type'] == 'Success') {
var output = info['URL'].substr(0, 64) + "expType=light&" + info['URL'].substr(64);
$("body").append('<form action="'+output+'" target="PPDGFrame" class="standard"><input type="submit" id="submitBtn"></form>');
$("#submitBtn").click();
} else {
alert("Error: Please try again or contact support.");
}
},
error : function () {
alert("Error: Please try again.");
}
});
}
At the bottom of the buttons page:
<script type="text/javascript" charset="utf-8">
var embeddedPPFlow = new PAYPAL.apps.DGFlow({trigger: 'checkout'});
</script>
I am thinking maybe it has to do with the order things are executed but can't seem to figure it out. Any help would be great!
EDIT: I just created a blank page and copied the script from the documentation exactly. I still get the same error. Might it have something to do with server settings? I am running a WampServer with an address like 192.168.1.1/mysite/index.html.
This is my code
chrome.windows.create({'url': "http://example.com/upload/upload.php?pictureID="+ theResponse + "&userID=" + localStorage["id"]+"&username="+ localStorage["mainLogin"]}, function(tab) {
// open window
});
this constructs a URL that looks like:
http://example.com/upload/upload.php?pictureID=123&userID=1&username=jack
I would call this method GET -- like how forms GET or POST
How can I open a window with POST data rather than GET data?
I think you have to write a HTML page that creates a form containing your POST data and target URL and submit the form.
Here's a simple example:
<html>
<head>
<script>
document.addEventListener('DOMContentLoaded', function()
{
location.search.substr(1).split('&').forEach(function(item)
{
var input = document.createElement('input');
input.type = 'hidden';
input.name = item.substr(0, item.indexOf('='));
input.value = item.substr(item.indexOf('=') + 1);
document.getElementById('postform').appendChild(input);
});
document.getElementById('postform').submit();
});
</script>
</head>
<body>
<form action="http://example.com/upload/upload.php" method="post" id="postform">
</form>
</body>
</html>
Say that's test.html in your extension's root directory. Call
chrome.windows.create({'url': "test.html?pictureID="+ theResponse + "&userID=" + localStorage["id"]+"&username="+ localStorage["mainLogin"]}, function(tab) {
// open window
});
will open the website with POST method.
I've wasted at least a half day of my company's time searching the Internet for an answer and I'm getting wrapped around the axle here. I can't figure out the difference between all the different technology choices (long polling, ajax streaming, comet, XMPP, etc.) and I can't get a simple hello world example working on my PC.
I am running Apache 2.2 and ActivePerl 5.10.0. JavaScript is completely acceptable for this solution. All I want to do is write a simple Perl CGI script that when accessed, it immediately returns some HTML that tells the user to wait or maybe sends an animated GIF. Then without any user intervention (no mouse clicks or anything) I want the CGI script to at some time later replace the wait message or the animated GIF with the actual results from their query.
I know this is simple stuff and websites do it all the time using JavaScript, but I can't find a single working example that I can cut and paste onto my machine that will work in Perl.
Here is my simple Hello World example that I've compiled from various Internet sources, but it doesn't seem to work. When I refresh this Perl CGI script in my web browser it prints nothing for 5 seconds, then it prints the PLEASE BE PATIENT web page, but not the results web page. So the Ajax XMLHttpRequest stuff obviously isn't working right. What am I doing wrong?
#!C:\Perl\bin\perl.exe
use CGI;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
sub Create_HTML {
my $html = <<EOHTML;
<html>
<head>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<script type="text/javascript" >
var xmlhttp=false;
/*#cc_on #*/
/*#if (#_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
#end #*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
</script>
<title>Ajax Streaming Connection Demo</title>
</head>
<body>
Some header text.
<p>
<div id="response">PLEASE BE PATIENT</div>
<p>
Some footer text.
</body>
</html>
EOHTML
return $html;
}
my $cgi = new CGI;
print $cgi->header;
print Create_HTML();
sleep(5);
print "<script type=\"text/javascript\">\n";
print "\$('response').innerHTML = 'Here are your results!';\n";
print "</script>\n";
If your process relies on query-string parameters, a simple meta-refresh would suffice. E.g. if they load http://yoursite.com/message?foo=1, then that can output a meta tag like:
<meta http-equiv="refresh" content="0; http://yoursite.com/realquery?foo=1" />
And some HTML that has your "please wait" message. The realquery script would actually execute the query and the HTML output by message will remain on the screen until realquery provides some output.
If the query relies on POST data, then it gets a little more complicated, because you can't redirect a POST. You can, however, output a form with some hidden fields and use Javascript to submit it. For example:
<script type="text/javascript">
window.onload = function() {
document.getElementById( 'form_with_hidden_fields' ).submit();
}
</script>
<form method="POST" action="realquery" id="form_with_hidden_fields">
<input type="hidden" name="foo" value="1" />
...
</form>
Please wait while your query is processed...
If you're interested in an AJAX solution, here's an example using jQuery:
$( '#submit-button' ).click( function() {
// show a "please wait" image
$( '#status-div' ).html( '<img src="please_wait.gif" />' ); // animated gif
// get form values
var formdata = { foo: $( 'input#foo' ).val(),
...
};
// submit form via ajax:
$.ajax( { type: "POST", url: "/realquery", data: formdata, success: function() {
$( '#status-div' ).html( '<img src="success.gif" />' );
} );
} );
And you could attach that to a form like:
<form>
<input type="text" name="foo" id="foo" />
<input type="submit" id="submit-button" />
<div id="status-div"> </div>
</form>
The empty status-div div will receive an image tag that points to a "please wait" image (this can be an animated gif). When the Ajax query finishes, it's replaced by a "success" image.
See Watching long processes through CGI by Randal Schwartz.
Here is a complete working example using friedo's HTTP meta refresh solution. This is not my personal first choice solution because it modifies the URL in the browser and it also refreshes the whole web page.
#!C:\Perl\bin\perl.exe
use CGI;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
sub html_page {
my ( $meta_string, $results_string ) = #_;
my $html = <<EOHTML;
<html>
<head>
$meta_string
<title>Two Stage Web Page Demo</title>
</head>
<body>
Some header text.
<p>
$results_string
<p>
Some footer text.
</body>
</html>
EOHTML
return $html;
}
my $cgi = new CGI;
print $cgi->header;
if ($cgi->param()) {
if ($cgi->param('doResults') eq "true") {
sleep(5);
print html_page('', 'Here are your results!');
}
}
else {
my $meta_refresh = '<meta http-equiv="refresh" content="0; /cgi-bin/twoStageScript.pl?doResults=true" />';
print html_page($meta_refresh, 'PLEASE BE PATIENT');
}
exit;
Finally got an Ajax version working. The slow.pl file is the file that takes a while to return.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Two Stage web page demo using Ajax</title>
</head>
<body>
<h1>Two Stage web page demo using Ajax</h1>
<div id="result">
Users input form goes here.
<p>
<input type="submit" value="Here is your submit button" id="load_basic" />
</div>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
$.ajaxSetup ({
cache: false
});
var ajax_load = "Please be patient, this could take a while. <p> <img src='img/load.gif'/>";
// load() function
$("#load_basic").click(function(){
$("#result").html(ajax_load).load("/cgi-bin/slow.pl");
});
</script>
</body>
</html>