Need help understanding this piece of code
-
Hi there, new on this forum and looking for help with some code I found at Cross Browser RDLC Printing - CodeProject. The author didn't include source or demo files and does not reply to my comments either, so I turned to this forum for help. The author supposedly shows a tip on how to create a print button for rdlc reportviewer for non IE browsers: **...If not, we should create a client-side print icon button on the fly. How to create one that exactly looks like the original print button? The answer is so straightforward, by copying the markup for the original button. Here is what RDLC uses for creating the print icon:
$print = $('
');
* Notice that we created a JavaScript object which represents the markup.
This icon must be added to the RDLC viewer toolbar and this is how to find the toolbar object on the client-side:
var findtoolbar = function () {
var $all = $('table div');
for (var i = 0, len = $all.length; i < len; i++) {
if ($($all[i]).css('background-image').toLowerCase().indexOf('toolbar_bk.png') != -1)
return $($all[i]);
}
return null;
}As you see, there is no solid identification method for the toolbar, so we used a combination of certain properties like background image along with the order of objects in the DOM...
Well he does not show WHERE and HOW to actually add the icon to the toolbar. I tried to do
$(document).ready(function () {
findtoolbar.add($print);
});and it threw an error (of course?), but with my limited knowledge of javascript and jquery, that's all I could come up with. So I was hoping someone here could help me make some sense out of this ;-). Thanks in advance.
The perfect woman: cooks good food and never says no in the middle of the night.**
-
Hi there, new on this forum and looking for help with some code I found at Cross Browser RDLC Printing - CodeProject. The author didn't include source or demo files and does not reply to my comments either, so I turned to this forum for help. The author supposedly shows a tip on how to create a print button for rdlc reportviewer for non IE browsers: **...If not, we should create a client-side print icon button on the fly. How to create one that exactly looks like the original print button? The answer is so straightforward, by copying the markup for the original button. Here is what RDLC uses for creating the print icon:
$print = $('
');
* Notice that we created a JavaScript object which represents the markup.
This icon must be added to the RDLC viewer toolbar and this is how to find the toolbar object on the client-side:
var findtoolbar = function () {
var $all = $('table div');
for (var i = 0, len = $all.length; i < len; i++) {
if ($($all[i]).css('background-image').toLowerCase().indexOf('toolbar_bk.png') != -1)
return $($all[i]);
}
return null;
}As you see, there is no solid identification method for the toolbar, so we used a combination of certain properties like background image along with the order of objects in the DOM...
Well he does not show WHERE and HOW to actually add the icon to the toolbar. I tried to do
$(document).ready(function () {
findtoolbar.add($print);
});and it threw an error (of course?), but with my limited knowledge of javascript and jquery, that's all I could come up with. So I was hoping someone here could help me make some sense out of this ;-). Thanks in advance.
The perfect woman: cooks good food and never says no in the middle of the night.**
Jaime Premy wrote:
with my limited knowledge of javascript and jquery,
The code you have posted is essentially a way to hack a webpage. So, having a limited knowledge or JavaScript is going to make this tough for you, which I suppose you already know. I suggest putting a breakpoint in the code and then seeing what it does. You're essentially trying to inject your own code into a Microsoft product and trick it into using what you have. In other words, I would be surprised if it worked all the time anyway. It is an unsupported hack. That article is also 2 years old and browsers have changed a bit since then. Also, the report viewer control I know changes often between versions so make sure you are using version 11, which is what the article says it supports.
There are only 10 types of people in the world, those who understand binary and those who don't.
-
Jaime Premy wrote:
with my limited knowledge of javascript and jquery,
The code you have posted is essentially a way to hack a webpage. So, having a limited knowledge or JavaScript is going to make this tough for you, which I suppose you already know. I suggest putting a breakpoint in the code and then seeing what it does. You're essentially trying to inject your own code into a Microsoft product and trick it into using what you have. In other words, I would be surprised if it worked all the time anyway. It is an unsupported hack. That article is also 2 years old and browsers have changed a bit since then. Also, the report viewer control I know changes often between versions so make sure you are using version 11, which is what the article says it supports.
There are only 10 types of people in the world, those who understand binary and those who don't.
Well my problem at this point is really how to add the js generated button to the toolbar. This hack is necessary since ms simply did not update reportviewer for compatibility with modern browsers, not even IE.
The perfect woman: cooks good food and never says no in the middle of the night.
-
Well my problem at this point is really how to add the js generated button to the toolbar. This hack is necessary since ms simply did not update reportviewer for compatibility with modern browsers, not even IE.
The perfect woman: cooks good food and never says no in the middle of the night.
I believe this code does it,
var findtoolbar = function () {
var $all = $('table div');
for (var i = 0, len = $all.length; i < len; i++) {
if ($($all[i]).css('background-image').toLowerCase().indexOf('toolbar_bk.png') != -1)
return $($all[i]);
}
return null;
}Like I said, this looks like a hack to inject your own code into existing MS product so there is no guarantee that it will work.
There are only 10 types of people in the world, those who understand binary and those who don't.
-
I believe this code does it,
var findtoolbar = function () {
var $all = $('table div');
for (var i = 0, len = $all.length; i < len; i++) {
if ($($all[i]).css('background-image').toLowerCase().indexOf('toolbar_bk.png') != -1)
return $($all[i]);
}
return null;
}Like I said, this looks like a hack to inject your own code into existing MS product so there is no guarantee that it will work.
There are only 10 types of people in the world, those who understand binary and those who don't.
Humm..., this is the code for finding the toolbar. My problem is how to ADD the javascript generated button to the toolbar...
The perfect woman: cooks good food and never says no in the middle of the night.
-
Humm..., this is the code for finding the toolbar. My problem is how to ADD the javascript generated button to the toolbar...
The perfect woman: cooks good food and never says no in the middle of the night.
Yes, I have understood you every time. What you are not getting is that you need to debug the code. I don't have the answer for you but that person took the time to write an article and I trust that it is correct. So, findtoolbar is code to find the toolbar but if it is in the article it's important for a reason. The $print part looks like it is the actual button. I believe, as I have stated, that findtoolbar is an existing Microsoft function that gets called already. The article, I believe, is hoping that this new findtoolbar function will get called instead of the built-in one and this new one works in chrome and firefox.
There are only 10 types of people in the world, those who understand binary and those who don't.