<HTML>
<HEAD>
<TITLE>Your Title Here</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
<CENTER><IMG SRC="ad.jpeg" ALIGN="BOTTOM"> </CENTER>
<script src="http://b.voicefive.com/c2/15770633/rs.js#c1=3&c3=2816501&c4=21996240&c5=3739279_170437&c6=&c10=&c11=170437&c13=225&c16=adtech&x=testInline()" type="text/javascript">
</script>
<script>
function testInline()
{
console.log("Hello World");
}
</script>
Now when the query parameters are passed in my javascript function it takes the last parameter x="testInLine()" as a string but I want it to take it as a function which I have written below.The objective is I want to call and execute 3rd party API's by passing them as query parameters. Help is appreciated. Thanks Swaraj
Something like this should do the trick:
var scriptSource = document.getElementsByTagName("script")[0].getAttribute("src");
// safer use document.getElementById("mySourceElement") instead, but you have
// give your script element the appropriate ID of course
window[scriptSource.substr(scriptSource.indexOf("x="))]();
You will likely want to add a better identifier/selector to your script element, perhaps an ID tag, but this should work, assuming you have only one script element on your page.
To use a value in the source, create the script tag by writing it from script:
<script type="text/javascript">
document.write('<scr'+'ipt src="http://b.voicefive.com/c2/15770633/rs.js#c1=3&c3=2816501&c4=21996240&c5=3739279_170437&c6=&c10=&c11=170437&c13=225&c16=adtech&x='+ testInline() + '" type="text/javascript"></scr'+'ipt>');
</script>
Remember to declare the testInline
function before this script.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.