/    Sign up×
Community /Pin to ProfileBookmark

Is this possible?

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. ?

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JJun 15.2003 — 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
Copy linkTweet thisAlerts:
@Mr_JJun 15.2003 — 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>
Copy linkTweet thisAlerts:
@ZeroauthorJun 15.2003 — This is good, but is there any way to make it search for a [i]particular[/i] 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... ?
Copy linkTweet thisAlerts:
@Mr_JJun 15.2003 — 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

[SIZE=1]

<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>

[/SIZE]
Copy linkTweet thisAlerts:
@ZeroauthorJun 15.2003 — 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?
Copy linkTweet thisAlerts:
@Mr_JJun 15.2003 — 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()

}
Copy linkTweet thisAlerts:
@ZeroauthorJun 15.2003 — I didn't think about that. Thanks. ?
Copy linkTweet thisAlerts:
@ZeroauthorJun 15.2003 — 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?
Copy linkTweet thisAlerts:
@ZeroauthorJun 15.2003 — [i]Originally posted by Dave Clark [/i]

[B]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? ?



[b]Dave[/b] [/B]
[/QUOTE]


At the moment, I've got this big slab of code hosted on my server, and all files are linked to it. ?
Copy linkTweet thisAlerts:
@Mr_JJun 15.2003 — 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>
Copy linkTweet thisAlerts:
@Khalid_AliJun 15.2003 — 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.
Copy linkTweet thisAlerts:
@ZeroauthorJun 16.2003 — [i]Originally posted by Khalid Ali [/i]

[B]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. [/B]
[/QUOTE]


Not if you're dealing with people that don't know what the hell they're doing. ?
×

Success!

Help @Zero spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...