Debt Consolidation - Valentine's Day Gifts - Debt Consolidation - Advertising - Loan

PDA

View Full Version : scanning javascrip result before displaying it


hextraordinary
Apr 11th 2007, 2:48 am
What I am trying to do it to skim through text received as a result of a javascript (and possible play around with it) before it is displayed on the page.

I can't get my head around how it should be done.

Felu
Apr 11th 2007, 2:51 am
I might be able to help you if you can explain what exactly you want.

hextraordinary
Apr 11th 2007, 3:00 am
well, i get an html (or any type of text for that matter) as a result from a javascript, what i want to do is scan that html page and look for specific keywords.

The real issue is doing that prior to it being displayed on the page.

Felu
Apr 11th 2007, 3:05 am
Just store the result in a variable and do the scanning, then display the page?

ajsa52
Apr 11th 2007, 10:59 am
For example, to replace "orig" with "dest" only inside a "idKeywords" HTML tag, you can use something like this:

<script type="text/javascript">

function f_InnerEnId( p_id, p_toInner )
{
try
{
document.getElementById( p_id ).innerHTML = p_toInner;
} catch(e) { }
}

function f_getElement(p_id)
{
l_text="";
try
{
l_elem=document.getElementById(p_id);
try
{
l_text+=l_elem.innerHTML;
} catch(e) { serializer1=new XMLSerializer(); l_text+=serializer1.serializeToString(l_elem); };
} catch(e) { }
return l_text;
}

var l_oldData = f_getElemento( "idKeywords" );
var l_pattern = /(orig)/g;
var l_newData = l_oldData.replace( l_pattern, 'dest' );
f_InnerEnId( "idKeywords", l_newData );

</script>


And instead of "orig" and "dest" it will be better with your own regular expressions.