|
you will get 0, 1 and 2
<a href="#">link 1</a>
<a href="#">link 2</a>
<a href="#">link 3</a>
<script type="text/javascript">
var anchorNiz = document.getElementsByTagName("a");
for(var i=0;i<anchorNiz.length;i++){
var anchor = anchorNiz[i];
anchor.attachEvent("onmouseover",(function(){
var arg = arguments[0];
return function(){
alert(arg);}})(i))
}
</script> also attachevent omly works in IE
modified on Tuesday, September 14, 2010 2:24 PM
|
|
|
|
|
thx. very interesting solution....
|
|
|
|
|
I want to use jQuery and jTemplates to display information returned via a webservice.
The code I am trying is:
function InsertAfter(RowID, json) {
var thisTable = document.getElementById("myTable");
var newRow = thisTable.insertRow(GetRowIndex(RowID));
newCell = newRow.insertCell(0);
newCell.colspan = '3';
newID = RowID + 'Results';
newCell.id = newID;
var template = $('#jTemplateResultsRow').html();
var item = $('#' + newID);
item.setTemplate(template);
item.processTemplate(json);
}
Everything goes fine til I get to the item.setTemplate(template); . Then I get a Microsoft JScript runtime error: Object doesn't support this property or method error.
I have double checked that both the jQuery and jTemplates libraries are loaded and that there are no conflicting javascript templates/frameworks/etc that are referenced.
Both the template and item get set to valid values.
Does anyone have any ideas or suggestions that could help?
---------------------------------------------------------------------
The issue was with the web service returning a nested json string.
All now works
modified on Wednesday, September 22, 2010 12:33 AM
|
|
|
|
|
You need to debug the javascript to see that template and item are both valid items. Depending on the development environment you are using, I tend to just put a debugger; statement in to force the app into the script debugger.
|
|
|
|
|
Thanks Pete,
I fixed this problem a couple of days ago, but forgot to update here.
The issue was mostly that the web service was returning a string with json inside json.
When I figured that out, it all just worked!
|
|
|
|
|
RCoate wrote: When I figured that out, it all just worked!
Good job
|
|
|
|
|
Hi,
Please verify item object which is set or not like set the debug point on following line
item.setTemplate(template);
and see whether item has any value if not then the problem is in following line
var item = $('#' + newID);
Thanks
sunaSaRa Imdadhusen
+91 99095 44184
+91 02767 284464
|
|
|
|
|
what is the best way to protect your javascript IP from being snatched and used without your permission? do you obfuscate, encrypt/decrypt your client side javascript?
thanks!
----------------------------------------------------------
Lorem ipsum dolor sit amet.
|
|
|
|
|
Obfuscate the client side scripting.
Here is an example site for doing just that;
http://www.javascriptobfuscator.com/[^]
I ran some code through and here is the example input and output;
function save_options() {
var currentID = localStorage["memberID"];
var newID = textMemberID.value;
if (!(currentID == newID)) {
localStorage["memberID"] = newID;
if (localStorage["memberID"] == newID) {
save_status.innerHTML = "MemberID: " + localStorage["memberID"] + " saved to local storage.";
setTimeout(function () { save_status.innerHTML = ""; }, 1000);
var newRep = new Array();
for (i = 0; i < 9; i++) {
newRep[i] = "0";
}
setNewRepDetail(newRep);
clearTable();
reload_Page();
}
else
{ save_status.innerHTML = "Error saving MemberID to localStorage."; }
}
else {
save_status.innerHTML = "MemberID: has not changed.";
setTimeout(function () { save_status.innerHTML = ""; }, 1000);
}
}
Output;
var _0x9c0d=["\x6D\x65\x6D\x62\x65\x72\x49\x44","\x76\x61\x6C\x75\x65","\x69\x6E\x6E\x65\x72\x48\x54\x4D\x4C","\x4D\x65\x6D\x62\x65\x72\x49\x44\x3A\x20","\x20\x73\x61\x76\x65\x64\x20\x74\x6F\x20\x6C\x6F\x63\x61\x6C\x20\x73\x74\x6F\x72\x61\x67\x65\x2E","","\x30","\x45\x72\x72\x6F\x72\x20\x73\x61\x76\x69\x6E\x67\x20\x4D\x65\x6D\x62\x65\x72\x49\x44\x20\x74\x6F\x20\x6C\x6F\x63\x61\x6C\x53\x74\x6F\x72\x61\x67\x65\x2E","\x4D\x65\x6D\x62\x65\x72\x49\x44\x3A\x20\x68\x61\x73\x20\x6E\x6F\x74\x20\x63\x68\x61\x6E\x67\x65\x64\x2E"];function save_options(){var _0xa035x2=localStorage[_0x9c0d[0]];var _0xa035x3=textMemberID[_0x9c0d[1]];if(!(_0xa035x2==_0xa035x3)){localStorage[_0x9c0d[0]]=_0xa035x3;if(localStorage[_0x9c0d[0]]==_0xa035x3){save_status[_0x9c0d[2]]=_0x9c0d[3]+localStorage[_0x9c0d[0]]+_0x9c0d[4];setTimeout(function (){save_status[_0x9c0d[2]]=_0x9c0d[5];} ,1000);var _0xa035x4= new Array();for(i=0;i<9;i++){_0xa035x4[i]=_0x9c0d[6];} ;setNewRepDetail(_0xa035x4);clearTable();reload_Page();} else {save_status[_0x9c0d[2]]=_0x9c0d[7];} ;} else {save_status[_0x9c0d[2]]=_0x9c0d[8];setTimeout(function (){save_status[_0x9c0d[2]]=_0x9c0d[5];} ,1000);} ;} ;
|
|
|
|
|
Yeah - and anyone can go to sites such as this[^] , or google elsewhere, and de-obfuscate it again.
It might be good for compression purposes, but you'd be an idiot to try hiding aything really imprtant in it, and a fool if you think your IP will be protected because of it.
Short answer tot eh OP's question is: you can't, so don't bother. The longer one is: why do you want to, really? Is there anything in your code that is so mind-blowing, and hasn't been done before, that you just have to stop anyone else from seeing it? Or learning from it...
|
|
|
|
|
Obfuscation is only good for deterring the casual code browser. I totally accept that.
|
|
|
|
|
Here is the code....it works fine on mozilla but on IE clearInterval doesn't work,,...
<br />
<html><br />
<head><br />
<style type="text/css"><br />
.imgf{width:300px; height:250px;}<br />
#img2{z-index:1000;}<br />
</style><br />
<script language="javascript"><br />
window.onload=inItAll;<br />
var j=0;<br />
var N=2;<br />
function inItAll()<br />
{<br />
document.getElementById("img1").onclick=click;<br />
}<br />
<br />
function click()<br />
{<br />
if(navigator.appName=="Netscape")<br />
{<br />
j=0.9;<br />
setInterval("fadeN()",40);<br />
<br />
}<br />
else<br />
{<br />
j=90;<br />
var fI = setInterval("fadeI()",40);<br />
}<br />
<br />
}<br />
<br />
function fadeN()<br />
{<br />
j=j-0.1<br />
<br />
if(j>0.4)<br />
{ <br />
<br />
document.getElementById("img1").style.opacity= j;<br />
}<br />
else<br />
{<br />
j=0.4;<br />
window.clearInterval();<br />
<br />
document.getElementById("img1").src = "images/"+2+".jpg";<br />
<br />
setInterval("showN()",40);<br />
<br />
} <br />
<br />
}<br />
<br />
function showN()<br />
{<br />
<br />
if(j<1)<br />
{<br />
document.getElementById("img1").style.opacity= j;<br />
j=0.1 + j;<br />
<br />
}<br />
else<br />
{<br />
window.clearInterval();<br />
document.getElementById("img1").style.opacity= 1;<br />
<br />
}<br />
}<br />
<br />
function fadeI()<br />
{<br />
j=j-10<br />
<br />
if(j>40)<br />
{ <br />
document.getElementById("img1").style.filter ="alpha(opacity="+j+")";<br />
<br />
}<br />
else<br />
{<br />
j=40;<br />
window.clearInterval(fI);<br />
<br />
document.getElementById("img1").src = "images/2.jpg";<br />
<br />
var sI = setInterval("showI()",40);<br />
} <br />
<br />
}<br />
<br />
function showI()<br />
{<br />
<br />
if(j<100)<br />
{<br />
document.getElementById("img1").style.filter ="alpha(opacity="+j+")";<br />
j=10 + j;<br />
<br />
}<br />
else<br />
{<br />
document.getElementById("img1").style.filter ="alpha(opacity="+100+")";<br />
window.clearInterval(sI);<br />
<br />
}<br />
}<br />
<br />
</script><br />
</head><br />
<body><br />
<center><br />
<br/><br />
<br/><br />
<div id="div1"><br />
<img src="images/1.jpg" class="imgf" id="img1"/><br />
</div> <br />
</center><br />
</body><br />
</html><br />
it gives unwanted flicks on IE coz clearInterval did not work.....
|
|
|
|
|
Try using JQuery[^]. Cross platform and much less to write.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I don't know anything about jquery......it's will take long to understand and implement that coz it's new technology for me...so plz can u help me with this in Javascript code....
Thnx...
|
|
|
|
|
Mmmm... did you even try to click on the link Mark provided ? Because I'm not sure anyone is gonna help you here if, on your side, you're not able to give yourself a little effort.
|
|
|
|
|
<script src=jquery-1.4.2.min.js />
$("#img1).fadeIn();
This is too difficult for you?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I used JQuery and JQueryUI in my last article, it was the first time i had even looked at JQuery, let alone actual go an implement it.
You should find it no problem at all, the basics are surprisingly simple.
|
|
|
|
|
EDIT:
OOps, sorry Mark, replied to the wrong message!
ignore it.
|
|
|
|
|
When you use setInterval you are supposed to set it to a variable, which becomes its ID, in effect - eg
instead of just writing
setInterval("showN()",40);
as you have, you should write
var IntervalID = setInterval("showN()",40);
Then, later when you want to clear it, you must refer to that ID:
clearInterval(intervalID);
Edit: screw jQuery. Never found a use for it yet. DIY, always.
|
|
|
|
|
NeverHeardOfMe wrote: screw jQuery. Never found a use for it yet. DIY, always.
That's what we need, more people who refuse to learn and espouse the "always been done that way" dictum.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Not at all - my "objection" to the likes of jQuery is precicely that it *stops* one from learning - it's just a box of magic tricks and turns you into a dancing dog. I prefer to try and learn how to do things myself.
Of course the reducto ad absurdum of this argument is that we should all go back to coding in machine language, and I am aware of that and the sillines of re-inventing the wheel. Nevertheless, I do feel there is a certian merit to my position - how often do we see questions asked here from people who have clearly learned a few "tricks" but have absolutely no real understanding of what they asking about?
|
|
|
|
|
JQuery is not a black box, you have the full source code available to actually research and learn. With .NET Reflector I'm often looking at Microsoft's code to see how something was done and learning.
You're argument is a bit weak but not worth the effort to drag out.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I modified da code and put var ID... = setInterval(....)...,
but now it says da ID i gave is unidentified by browsers(both IE and Firefox).....
<br />
window.onload=inItAll;<br />
var j=0;<br />
var N=2;<br />
function inItAll()<br />
{<br />
document.getElementById("img1").onclick=click;<br />
}<br />
<br />
<br />
function click()<br />
{ <br />
<br />
if(navigator.appName=="Netscape")<br />
{<br />
j=0.9;<br />
<br />
var IntervalIDN1 = setInterval("fadeN()",40);
<br />
<br />
}<br />
else<br />
{<br />
j=90;<br />
var IntervalIDI1 = setInterval("fadeI()",40);
}<br />
<br />
}<br />
<br />
function fadeN()
{<br />
j=j-0.1<br />
<br />
if(j>0.4)<br />
{ <br />
<br />
document.getElementById("img1").style.opacity= j;<br />
}<br />
else<br />
{<br />
j=0.4;<br />
window.clearInterval(IntervalIDN1);<br />
<br />
document.getElementById("img1").src = "images/"+N+".jpg";<br />
<br />
var IntervalIDN2 = setInterval("showN()",40);<br />
<br />
} <br />
<br />
}<br />
<br />
function showN()
{<br />
<br />
if(j<1)<br />
{<br />
document.getElementById("img1").style.opacity= j;<br />
j=0.1 + j;<br />
<br />
}<br />
else<br />
{<br />
window.clearInterval(IntervalIDN2);<br />
document.getElementById("img1").style.opacity= 1;<br />
<br />
}<br />
}<br />
<br />
function fadeI()
{<br />
j=j-10<br />
<br />
if(j>40)<br />
{ <br />
document.getElementById("img1").style.filter ="alpha(opacity="+j+")";<br />
<br />
}<br />
else<br />
{<br />
j=40;<br />
window.clearInterval(IntervalIDI1);<br />
<br />
document.getElementById("img1").src = "images/2.jpg";<br />
<br />
var IntervalIDI2 = setInterval("showI()",40);<br />
} <br />
<br />
}<br />
<br />
function showI()
{<br />
<br />
if(j<100)<br />
{<br />
document.getElementById("img1").style.filter ="alpha(opacity="+j+")";<br />
j=10 + j;<br />
<br />
}<br />
else<br />
{<br />
document.getElementById("img1").style.filter ="alpha(opacity="+100+")";<br />
window.clearInterval(IntervalIDI2);<br />
<br />
}<br />
}<br />
if i remove ids it works perfectly on Firefox but not on IE....
|
|
|
|
|
well you need to define the var IntervalID outside of the functions (so that it is globally accessible to all), and then justs et it within
var IntervalID;
...
function XYZ () {
IntervalID = ...
}
|
|
|
|
|