Zero
06-15-2003, 01:26 AM
I want a JavaScript that will read the HTML Page for a specific line. If that line is changed or removed I want the page to re-direct to a different page. Any help?
Thanks. :D
Thanks. :D
|
Click to See Complete Forum and Search --> : Is this possible? Zero 06-15-2003, 01:26 AM I want a JavaScript that will read the HTML Page for a specific line. If that line is changed or removed I want the page to re-direct to a different page. Any help? Thanks. :D Mr J 06-15-2003, 03:06 AM Probably ...... You could put the text in an DIV with an ID and then get the script to check if the DIV exists and validate its contents Mr J 06-15-2003, 04:18 AM Here is an example: The script checks to see if "mydiv" exists and then gives the appropriate response <HTML> <HEAD> <TITLE>Document Title</TITLE> <script> present=0 function chk(){ how_many=document.getElementsByTagName("DIV").length for(i=0;i<how_many;i++){ if(document.getElementsByTagName("DIV")[i].id=="mydiv"){ present=1 display.innerHTML="The contents of mydiv are:<font color=\"red\"> "+document.getElementsByTagName("DIV")[i].innerText+"<font>" } } if(!present){ display.innerHTML="<font color=\"red\" size=\"7\">mydiv does not exist</font>" } } </script> </HEAD> <BODY> <a href="#null" onclick="chk()">CLICK ME</a> <P><div>Sample Div1</div><div>Sample Div2</div><div>Sample Div3</div><div>Sample Div4</div><div>Sample Div5</div> <div id="mydiv">Hello World</div> <div>Sample Div6</div><div>Sample Div7</div><div>Sample Div8</div><div>Sample Div9</div><div>Sample Div10</div> <div id="display"></div> </BODY> </HTML> Zero 06-15-2003, 05:15 AM This is good, but is there any way to make it search for a particular line inside the tag? Example, I'm placing this in some code that I'm releasing for public use. I want the copyright to stay intact, so I integrate this script in with another that controls a major aspect of the rest of the code. Well, you can change what's in the DIV tags. I want it to make sure that you can't even change what's in the DIV tags... ;) Mr J 06-15-2003, 08:17 AM Ok lets see if I am reading you right, You have a script that you are going to allow others to use but want to make sure they don't take out the copywrite. If you have access to the document source then anything can be changed and no amount of safeguards can prevent this. Still, take a look at this. Click the link and notice nothing changes Now go into the source and in "mydiv" delete the text "INTACT COPYWRITE" Refresh the page and click the link again. You should see that the text "INTACT COPYWRITE" has been added <HTML> <HEAD> <TITLE>Document Title</TITLE> </HEAD> <BODY> <script> present=0 function chk(){ how_many=document.getElementsByTagName("DIV").length for(i=0;i<how_many;i++){ if(document.getElementsByTagName("DIV")[i].id=="mydiv"){ present=1 mydiv_content=mydiv.innerHTML chk_content() } } } message="INTACT COPYWRITE" // text to check for var win = window; var n = 0; function chk_content() { var txt, i, found; if (message == "") return false; txt = win.document.body.createTextRange(); for (i = 0; i <= n && (found = txt.findText(message)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); } if (!found) { mydiv.innerHTML=mydiv_content+" "+message } } </script> <a href="#null" onclick="chk()">CLICK ME</a> <P><div>Sample Div1</div><div>Sample Div2</div><div>Sample Div3</div><div>Sample Div4</div><div>Sample Div5</div> <P><div id="mydiv">Information to be included. INTACT COPYWRITE</div> <P><div>Sample Div6</div><div>Sample Div7</div><div>Sample Div8</div><div>Sample Div9</div><div>Sample Div10</div> </BODY> </HTML> Zero 06-15-2003, 08:36 AM Yes...this is perfect. Now I need to get it to work with another file calling the body onload function. I've been trying to get it to work with this code: function setActiveStyleSheet(title) { var i, a, main; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { a.disabled = true; if(a.getAttribute("title") == title) a.disabled = false; } } } function getActiveStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); } return null; } function getPreferredStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") ) return a.getAttribute("title"); } return null; } function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } window.onload = function(e) { var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title); } window.onunload = function(e) { var title = getActiveStyleSheet(); createCookie("style", title, 365); } var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title); Any suggestions? Mr J 06-15-2003, 08:51 AM Instead of calling function chk() with a link could you not use onload? or place it in here window.onload = function(e) { var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title); chk() } Zero 06-15-2003, 08:56 AM I didn't think about that. Thanks. :) Zero 06-15-2003, 09:00 AM Okay...one more question, while I'm here... Is it possible to make it accept multiple lines, where if at least one of the distinguished lines are there, it doesn't produce the alert? Zero 06-15-2003, 09:05 AM Originally posted by Dave Clark Perhaps I don't understand your complete scenario but, if they can change what is in the DIV block, surely they can also remove the script that is checking for what is in the DIV block. Yes? ;) Dave At the moment, I've got this big slab of code hosted on my server, and all files are linked to it. :) Mr J 06-15-2003, 12:09 PM Although I am not absolutely sure see if this does the trick. In the script there is now an array that contains 2 strings These are INTACT COPYWRITE and TESTING TEXT These 2 strings are what the script is going to check for. Initially these are included in the "mydiv" div As before delete one of these from the "mydiv" div so that the script can check to see whats missing. <HTML> <HEAD> <TITLE>Document Title</TITLE> </HEAD> <BODY> <script> present=0 function chk(){ how_many=document.getElementsByTagName("DIV").length for(i=0;i<how_many;i++){ if(document.getElementsByTagName("DIV")[i].id=="mydiv"){ present=1 mydiv_content=mydiv.innerHTML chk_content() } } } message=new Array("INTACT COPYWRITE","TESTING TEXT") // text to check for var win = window; var n = 0; c=0 function chk_content() { for(h=0;h<message.length;h++){ var txt, i, found; if (message[h] == "") return false; txt = win.document.body.createTextRange(); for (i = 0; i <= n && (found = txt.findText(message[h])) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); } if (found) { } if (!found) { if(h==0){add_message=message[0]} if(h==1){add_message=message[1]} mydiv.innerHTML+=" "+add_message } } } </script> <a href="#null" onclick="chk()">CLICK ME</a> <P><div>Sample Div1</div><div>Sample Div2</div><div>Sample Div3</div><div>Sample Div4</div><div>Sample Div5</div> <P><div id="mydiv">Information INTACT COPYWRITE TESTING TEXT to be included. </div> <P><div>Sample Div6</div><div>Sample Div7</div><div>Sample Div8</div><div>Sample Div9</div><div>Sample Div10</div> </BODY> </HTML> Khalid Ali 06-15-2003, 12:17 PM If you are trying to protect your code from being used by some one else without your permission?.. then whatever you are doing on the client side is useles.Te internet by "default" was open source and so far it has managed to be that way...If you want to protect your code use server side..at the end of the day ...nothing is protected on the client side coding.. Don't waste your energy and time. Zero 06-15-2003, 07:34 PM Originally posted by Khalid Ali If you are trying to protect your code from being used by some one else without your permission?.. then whatever you are doing on the client side is useles.Te internet by "default" was open source and so far it has managed to be that way...If you want to protect your code use server side..at the end of the day ...nothing is protected on the client side coding.. Don't waste your energy and time. Not if you're dealing with people that don't know what the hell they're doing. ;) webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |