I am trying to get the following value from the script below Use this field to store the Account to which the Opportunity is related
<script>sfdcPage.setHelp('Opportunity.Account', 'Use this field to store the Account to which the Opportunity is related');</script>
i can get to this script tag by using :
document.getElementsByTagName('tbody')[6].getElementsByTagName('script')[1];
Can you please let me know. Many thanks.
I am trying to get the following value from the script below Use this field to store the Account to which the Opportunity is related
<script>sfdcPage.setHelp('Opportunity.Account', 'Use this field to store the Account to which the Opportunity is related');</script>
i can get to this script tag by using :
document.getElementsByTagName('tbody')[6].getElementsByTagName('script')[1];
Can you please let me know. Many thanks.
Share Improve this question asked Jul 24, 2013 at 12:38 SamSam 4874 gold badges12 silver badges32 bronze badges 3- let us see the website that you're trying this code on. – Okan Kocyigit Commented Jul 24, 2013 at 12:42
-
There is a property called
innerHTML
; – Mārtiņš Briedis Commented Jul 24, 2013 at 12:42 -
Without knowing the prototype for the sfdcPage, it's hard to give a better option. You can get the content of the script (if it's a part of the page, as opposed to being a linked-to script) by using it's innerText member. i.e
document.getElementsByTagName('tbody')[6].getElementsByTagName('script')[1].innerText
From there, you could just grab all of the text between the 3rd and 4th'
characters. indexOf and substr will do that for you. – enhzflep Commented Jul 24, 2013 at 12:48
3 Answers
Reset to default 3I would not remend putting script
tags within your tables, etc. In other words, I wouldn't mix script
tags with other content-related HTML like that. If you want to store little bits of info like that in your HTML for the purpose of JS, I'd use data attributes instead.
The simple answer to your question though is to just use the innerHTML
or innerText
property as follows:
document.getElementsByTagName('tbody')[6].getElementsByTagName('script')[1].innerHTML;
Use innerHtml as
document.getElementsByTagName('tbody')[6].
getElementsByTagName('script')[1].
innerHtml;
OR
Set an id to get script content as below example
<script id='script' type='text/javascript'>
$('div').html($('#script').html());
console.log($('script'));
</script>
fiddle
There are lots of ways to do this. One solution....
var scrs = document.getElementsByTagName('script');
var newscr = "";
for (var i=0; i<scrs.length; i++) {
newscr = scrs[i].innerHtml.replace('sfdcPage.setHelp(', 'myfunction(');
if (newscr != scrs[i].innerHtml) {
eval(newscr);
}
}
(although parsing / rewriting the javascript is an ugly hack - if it's your code then your reading then you should know what you put in there).