jquery.printElement not responding at all - javascript

I've been trying to use the jquery.printElement plugin but nothing happens when I click on the Print link, except for this error message in the console:
Uncaught TypeError: Cannot read property 'opera' of undefined
The code I'm using is as follows:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Print</title>
</head>
<body>
<p id="content">Some text to print</p>
Print
<script src="../common/js/jquery-1.10.1.min.js"></script>
<script src="../common/js/jquery.printElement.js"></script>
<script>
$('#printIt').click(function() {
$('#content').printElement();
});
</script>
</body>
</html>
Anyone know why this is happening?

The printElement plugin uses jQuery.browser internally, and $.browser has been deprecated and removed in the version of jQuery you're using.
You have to use an older version of jQuery, or possibly the migrate plugin to make printElement work.

wrap code inside document.ready.
$(function()
{
$('#printIt').click(function()
{
$('#content').printElement();
});
});

Related

How to import pdf.js using cdn

I wanted to use pdf.js for a project of mine but I faced an issue of importing it, basically, the CDN doesn't work
Here is my code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist#2.7.570/build/pdf.min.js"></script>
</head>
<body>
<canvas id="my-canvas"></canvas>
<script>
pdfjsLib.getDocument('./ahmed.pdf').then(doc => {
console.log("this file has" + doc._pdfInfo.numPages);
});
</script>
</body>
</html>
and that is the errors that my console shows
Deprecated API usage: No "GlobalWorkerOptions.workerSrc" specified.
Uncaught TypeError: pdfjsLib.getDocument(...).then is not a function
So what should i do to solve this problem and thank you so much
You have to set GlobalWorkerOptions.workerSrc to /build/pdf.worker(.min).js of same version:
pdfjsLib.GlobalWorkerOptions.workerSrc =
"https://cdn.jsdelivr.net/npm/pdfjs-dist#2.7.570/build/pdf.worker.min.js"; 👈
pdfjsLib.getDocument('./ahmed.pdf').promise.then(doc => {
console.log(`This document has ${doc._pdfInfo.numPages} pages.");
});
And, as #Pasi has mentioned, you have to promisify .getDocument() by chaining .promise on it. Without it, there is no .then().
See the "Hello World with document load error handling" example on this page to get started: https://mozilla.github.io/pdf.js/examples/
(Your snippet is missing .promise after getDocument() and setting the workerSrc property)

simple jquery didnt work, and returning error

I have simple code to hide and show paragraph, and using jquery as the trigger
suddenly my jquery return errors,this is the error
SyntaxError: expected expression, got '<'
http://localhost/portofolio1/navigation_test.php/jquery-2.1.3.js
Line 1
ReferenceError: $ is not defined
http://localhost/portofolio1/navigation_test.php/
Line 9
if i use cdn it work perfectly as usual
this is my simple code to test my jquery
<!DOCTYPE html>
<html>
<head>
<title>Simple list</title>
<!-- <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>-->
<script src="jquery-2.1.3.js"></script>
<script>
$(function () {
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
<button onclick="">SHOW ALERT</button>
</body>
</html>
SOLVED
after i create new .php file and move ALL the code to the new file, it
work normal, i dont know the problem, this sure really weird
Mind the quotes:
<script src="./jquery-2.1.3.js"></script>
type is optional by the way.
Also check if http://localhost/portofolio1/navigation_test.php/jquery-2.1.3.js is pointing to jQuery. From the looks of your error, the script is pointing to something not jQuery, possibly an error page, hence SyntaxError: expected expression, got '<'. This error means that the browser expected a script, but returned HTML (signified by the script meeting an unexpected <).

HTML5/javascript error

If I run the below code as regular html5 code in the browser, Its works fine. I want the same result using android. I am getting the following error:
12-08 12:56:26.546: ERROR/Web Console(703): TypeError: Result of
expression 'service.useService' [undefined] is not a function. at
file:///android_asset/www/index.html:12
<!DOCTYPE HTML>
<html>
<head>
<title>Hello World</title>
<script language="JavaScript">
var iCallID;
function InitializeService()
{
service.useService("http://10.15.1.205/HelloService/Service.asmx?wsdl", "HelloWorldService");
service.HelloWorldService.callService("HelloWorld");
}
function ShowResult()
{
document.write(event.result.value);
}
</script>
</head>
<body onload="InitializeService()" id="service" style="behavior:url(webservice.htc)" onresult="ShowResult()">
</body>
</html>
This isnt a problem with HTML5 this is a Internet Explorer only CSS attribute -> http://msdn.microsoft.com/en-us/library/ms530723(v=vs.85).aspx
Cannot find it in any official HTML5 / CSS3 documentation ...
So unless your Android device runs Internet Explorer you need to find an alternative

head.js and jQuery issues in Chrome / Firefox 5

So the page is rendered like this:
<!DOCTYPE html>
<html>
<head>
<script>
head.js("js/jquery.js",
"js/jquery.autocomplete.js");
</script>
</head>
<body>
...
stuff here
...
<script>
jQuery(document).ready(function($){ // fail...
$('body').removeClass('no-jquery');
// ...
});
</script>
</body>
</html>
The scripts seem to load and all in Opera, but in Firefox 5 and Chrome (don't know the version because it changes every day) I get a error:
jQuery is not defined
[Break On This Error] jQuery(document).ready(function($){
So I guess jquery is not really loaded by head.js in these browsers? Or I'm doing something wrong?
jsfiddle: http://jsfiddle.net/LDUUd/
Try switching to head.ready() instead of jQuery.ready().
Here is an example of it working - is this what you have?
You're calling head.js() without
<!-- assuming it's in the same directory as the page -->
<script src="head.min.js"></script>
first.

Uncaught reference error: quickread is not defined

I get an UncaughtReferenceError: QuickRead is not defined on line 10 which is QuickRead.applyToLinks();
I am using the script from here http://www.readshout.com/quickread and I believed I followed all the directions it has to use it, yet its not working.
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<script language="JavaScript" type="text/javascript" src="http://www.readshout.com/bookmarklets/quickread/quickread.js"></script>
<script>
//QuickRead.setFilter('a.my_links');
QuickRead.applyToLinks();
</script>
Give up on google<br />
ycomb exp
</body>
</html>
Works for me. You could however try to add jQuery 1.4.2 manually, as QuickRead seems to dynamically load it. Otherwise try Firebug to find the error.

Categories

Resources