0 is null or not an object error - javascript

Am using the following javascript programm for convert pdf file to binary file .It will work properly in FireFox.but in IE it will display the "0 is null or not an object javascript" .how to solve this?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function(){
$('#document_upload').change(function()
{
var fileList = this.files;
var file = fileList[0];
create_blob(file,function(blob_string)
{
replace_binary_data=blob_string;
$("#document_binary").val(replace_binary_data);
});
});
function create_blob(file, callback)
{
var reader = new FileReader();
reader.onload = function()
{
callback(reader.result)
};
reader.readAsDataURL(file);
}
});
</script>
<body>
<input type="text" id="document_binary" value=""/>
<div id="upload_document">
<input type="file" name="document" id="document_upload"/>
</div>
</body>
</html>

I'm pretty sure IE does not support FileReader (so you cannot instantiate it for obvious reasons).
See http://caniuse.com/filereader - it is not available until IE10.

Related

Object PDF Viewer does not Render large File with over 2.0 MB in chrome

Sorry if this question might have been asked before but I am trying to show a preview of pdf document before upload and only work for pdf less than 1Mb of data. Any data above this does not seem to show in my browser. I am using chrome. Here is my XHTML code which works for less than 1MB pdf files.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
<script type="text/javascript">
//<![CDATA[
function renderPDF(input)
{
if (input.files && input.files[0])
{
var reader = new FileReader();
reader.onload = function (e)
{
$('#p_viewer').attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
//]]>
</script>
</h:head>
<h:body>
<div class="row">
<div class="col-md-4">
<h:form id="uploader_form" enctype="multipart/form-data">
<h:inputFile value="#{up.file}" onchange="renderPDF(this)" />
</h:form>
</div>
<div class="col-md-8">
<p:outputPanel id="out">
<iframe frameborder="0" height="600" width="100%" id="p_viewer" type="application/pdf">
</iframe>
</p:outputPanel>
</div>
</div>
</h:body>
</html>
Or is there another way to show pdf document in JSF prior to upload submit button is clicked?

<Object> tag does not work in android webview

The pdf file does not read from assert folder.
tag does not work in android webview
WebView webview = new WebView(this);
string url = "file:///android_assets/test.pdf";
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(url);
Want to load the below HTML file in webview.
Need to Load pdf, word, excel, ppt.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script src="js/jquery-ui.js" type="text/javascript"></script>
<link href="css/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
var fileName = "Tulips.txt";
$("#btnShow").click(function () {
$("#dialog").dialog({
modal: true,
title: fileName,
width: 540,
height: 450,
buttons: {
Close: function () {
$(this).dialog('close');
}
},
open: function () {
var object = "<object data=\"{FileName}\" width=\"500px\" height=\"300px\">";
object += "</object>";
object = object.replace(/{FileName}/g, "Files/" + fileName);
$("#dialog").html(object);
}
});
});
});
</script>
<input id="btnShow" type="button" value="Show PDF" />
<div id="dialog" style="display: none">
</div>
</body>
</html>
Kindly let me know if any other possibilities to convert PDF, Word & Excel into HTML with help of android webview.
Your URL would appear to be to to a PDF. WebView cannot display a PDF.

Unable to play video with VLC activeX plugin in IE9 and earlier

I am trying to play a video in IE9 and earlier versions. For that I used activeX plugin to load VLC Media Player (that is my basic requirement).
When I tried to execute my code I got an error thrown:
Unable to get value of the property 'playlist': object is null or undefined
My code as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>VLC API</title>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script>
$(document).ready(function(){
play();
displayPlugins();
$(function(){
$("#vlc").css({ "width": "400px", "height": "300px" });
});
});
function play()
{
var vlc=document.getElementById("vlc");
alert("play video");
var url="rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";
var options=new Array(":aspect-ratio=4:3","-rtsp-tcp");
var id= vlc.playlist.add(url,"",options);
vlc.playlist.playItem(id);
}
function displayPlugins()
{
alert("plugins");
var player="<object type='application/x-vlc-plugin' id='vlc' width='300' height='225' classid='clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921' codebase='http://activex.microsoft.com/controls/vb5/comdlg32.cab'></object>";
$("#video_holder").html(player);
}
</script>
</head>
<body>
<div id="video_holder" style="border:1px solid #00FF33; height:350px;"></div>
</body>
Can anybody help me where I'm getting wrong?
You are doing:
var vlc=document.getElementById("vlc");
But on HTML, you have
<div id="video_holder" style="border:1px solid #00FF33; height:350px;"></div>
So in theory you want:
var vlc=document.getElementById("video_holder");
You might have more problems after that, but start here.

JQuery dynamic search results not working

I am new to JQuery and I am trying to make a search box. When I type in the search box it doesn't do anything and I don't know why. Any help would be appreciated. Here is my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Test</title>
</head>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var $cells = $("td");
$("#search").keyup(function() {
var val = $.trim(this.value).toUpperCase();
if (val === "")
$cells.parent().show();
else {
$cells.parent().hide();
$cells.filter(function() {
return -1 != $(this).text().toUpperCase().indexOf(val); }).parent().show();
}
});
});​
</script>
<form action="" method="post">
<label for="search">Search</label>
<input type="text" name="search" id="search" class="inputfield" />
</form>
<table border="0" align="left">
<tr><td>Gripper 25x8-12 GR25812</td></tr>
<tr><td>Gripper 25x10-12 GR251012</td></tr>
<tr><td>Gripper 26x9-12 GR26912</td></tr>
<tr><td>Gripper 26x12-12 GR261212</td></tr>
</table>
</body>
</html>
This is working code I have tried it in Fiddle and it works
Try to search 25x in input box you will find the output.
Updated
May be there are some zero-width spaces between your code,
I check and I got Error in your code like,
Uncaught SyntaxError: Unexpected token ILLEGAL
Reference Chrome Uncaught Syntax Error: Unexpected Token ILLEGAL
And if you rewrite above code like,
$(function(){
var $cells = $("td");
$("#search").keyup(function() {
var val = $.trim($(this).val()).toUpperCase();
if (val === "")
$cells.parent().show();
else {
$cells.parent().hide();
$cells.filter(function() {return -1 != $(this).text().toUpperCase().indexOf(val);}).parent().show();
}
});
})
Then I found it works

Javascript variable not refreshing in Phonegap application

I have just written my first app in phonegap that simply replaces a text string on the screen each time you activate a link.
The original string stays where it is and the new string is written over the top. If you then activate the link again the second string is replaced with a new one but still over the top of the first string.
I have tried clearing the variable to fix this but no luck.
Is this a platform limitation or am i doing something wrong?
Code is below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body onload="newIdea()">
<h1 class="h1">First Love</h1>
<p>Have you ever? </p>
<h3><div id="ideaDiv">Nothing</div></h3>
Let's Do it
No Thanks
<script type="text/javascript">
var ideas=new Array(); // regular array (add an optional integer
ideas[0]="Kissed someone in the rain"; // argument to control array's size)
ideas[1]="Eaten peking duck";
ideas[2]="Stood naked in the open";
function newIdea(){
var idea = "";
var idea = ideas[Math.floor(Math.random()*ideas.length)];
var ideaSpace = document.getElementById("ideaDiv");
ideaSpace.innerHTML=idea;
var ideaLink=document.getElementById("ideaLink");
var linkCreate="http://www.google.com/calendar/event?action=TEMPLATE&text=" + idea + "&dates=20120101/20120102&details=&location=&trp=false&sprop=&sprop=name:";
ideaLink.href=linkCreate;
}
</script>
</body>
</html>
Thanks
Simon
I have no experience with phonegap, but in the past I found some problems trying to set innerHTML in xhtml documents, it don't check if the string you are using causes the document to still a valid xml and just throws an error, to achieve the same effect try:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body onload="newIdea()">
<h1 class="h1">First Love</h1>
<p>Have you ever? </p>
<h3><div id="ideaDiv">Nothing</div></h3>
Let's Do it
No Thanks
<script type="text/javascript">
var ideas=new Array(); // regular array (add an optional integer
ideas[0]="Kissed someone in the rain"; // argument to control array's size)
ideas[1]="Eaten peking duck";
ideas[2]="Stood naked in the open";
function newIdea(){
var idea = "";
var idea = ideas[Math.floor(Math.random()*ideas.length)];
var ideaSpace = document.getElementById("ideaDiv");
//ideaSpace.innerHTML=idea;
ideaSpace.removeChild(ideaSpace.firstChild);
ideaSpace.appendChild(document.createTextNode(idea));
var ideaLink=document.getElementById("ideaLink");
var linkCreate="http://www.google.com/calendar/event?action=TEMPLATE&text=" + idea + "&dates=20120101/20120102&details=&location=&trp=false&sprop=&sprop=name:";
ideaLink.href=linkCreate;
}
</script>
</body>
</html>

Categories