Auto-search webpage for text, w/ refresh

Subscribe to Auto-search webpage for text, w/ refresh 37 posts, 9 voices

sizzlemctwizzle Scriptwright

@JoeSimmons

I've taken Chris D's method and put it into a function if anyone needs a simple, quick way to search the html of the body...

Yeah my method actually and it doesn't search the html at all, just the text content.

"Every day above ground is a good day."

 
Avindra V.G. Scriptwright

with "can't", you must have to do:

"//child::text()[contains(\"can't\")]"

 
Tim Smart Scriptwright

Would it be faster to do a evaluate call, rather than a call on the innerHTML after the page has initialized?

 
Aquilax Scriptwright

@avg

Yes I know about it, I was just telling JoeSimmon that he has to escape the "text" parameter of his function before adding it to the xpath. Try to escape for an xpath the following text: Can't "escape" this!

 
Avindra V.G. Scriptwright

You can do that as well:

"Can't \"escape\" this!"

 
Aquilax Scriptwright

I know how to escape string, I'm saying that is not possible to escape it inside an xpath, try it if you think that you can do it.


document.evalute("//child::text()[contains(...)]",document,null,9,null);

 
znerp Scriptwright

I'm reading these posts between Aquilax and avg, and I don't understand where the communication is breaking down.

avg, look at Joe's function here and then read Aquilax's reply here.

 
Avindra V.G. Scriptwright

"//child::text()[contains(\"hello there! i am \\\"escaped\\\"\")]"

wouldn't that do it for hello there! i am "escaped"
?

@znerp: Doesn't really matter where it started; this is an interesting issue regardless.

 
JoeSimmons Scriptwright

// Search body's inner html
function searchDoc(t) {
	return document.evaluate("//child::text()[contains(.,'"+t+"')]",document,null,9,null).singleNodeValue!=null;
}

alert(searchDoc("wouldn't"));

Doesn't work no matter what you try. I tried adding slashes, using addslahes(t) and all.


"None are more hopelessly enslaved than those who falsely believe they are free." - Johann Wolfgang von Goethe

 
znerp Scriptwright
Doesn't really matter where it started; this is an interesting issue regardless.

It's relatively interesting, yes, but you seemed to be trying to give a lesson on escaping characters but I think everyone here knows how to escape quotes.

 
Aquilax Scriptwright


Doesn't work no matter what you try. I tried adding slashes, using addslahes(t) and all.

I've google it a little bit and seems to be a problem of xpath 1.0, which doesn't define any escape method. Most of the people suggested to use the concat function. I didn't test it but you should be able to do something like this one:


contains(.,concat("can't escape",'"',"this",'"'))
of if you prefer
contains(.,concat('can',"'",'t escape "this"'))

 
Avindra V.G. Scriptwright

It's relatively interesting, yes, but you seemed to be trying to give a lesson on escaping characters but I think everyone here knows how to escape quotes.

I appreciate that everyone knows how to escape. Clearly however, there is an issue... otherwise this discussion would be nonexistent. Did anyone try my string suggestion? I'm not sure if it'll work, and I haven't tried it. It was:

FOR TESTING:

hello there! i am "escaped"

"//child::text()[contains(\"hello there! i am \\\"escaped\\\"\")]"

EDIT: Appears that this does not work....

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel