-1

My client puts our below JS code in his website in the <head> and is complaining our tags are not firing. Below is the sample code from client:

    <html>
    <head>
    <script type="text/javascript">
    function create() {
    try {
    var baseURL = "https://serv2ssl.vizury.com/analyze/analyze.php?account_id=VIZVRM1125";
    var analyze = document.createElement("iframe");
    analyze.src = baseURL;
    var node = document.getElementsByTagName("script")[0];
    node.parentNode.insertBefore(analyze, node);
} catch (i) {
}
}
 var existing = window.onload;
window.onload = function() {
if (existing) {
    existing();
}
create();
}
  </script>
 </head>

 <body onload="javascript:clientfunction();">
 <script type="text/javascript">

function clientfunction()
{
   //client code is replcad here
   document.write("Hello testing");
}
 </script>

  </body>
 </html>

On page Load clientfunction() is calling, our create() function is not firing.

Please can anybody help me why our tags are not firing and what is the alternative solution for this issue?

user229044
  • 232,980
  • 40
  • 330
  • 338
daya
  • 1
  • 1

1 Answers1

-1

copy paste and check running following

<html>
<head>
<script type="text/javascript">
function create() {
alert("Gdfg");
try {
var baseURL = "https://serv2ssl.vizury.com/analyze/analyze.php?account_id=VIZVRM1125";
var analyze = document.createElement("iframe");
analyze.src = baseURL;
var node = document.getElementsByTagName("script")[0];
node.parentNode.insertBefore(analyze, node);
} catch (i) {
}
}

window.onload=create;
window.onload=clientfunction;
</script>
</head>

<body onload="clientfunction(); create()">
<script type="text/javascript">

function clientfunction()
{
alert("fdsfsdf");
//client code is replcad here
document.write("Hello testing");
}
</script>

</body>
</html>
Sunil Verma
  • 2,490
  • 1
  • 14
  • 15
  • 1
    Only the bottom executes, doesn't it? – Qantas 94 Heavy Sep 27 '13 at 14:26
  • no both are working fine, i am editing my post to give you complete code. – Sunil Verma Sep 27 '13 at 14:28
  • @SKV Both are working fine because you've stuck them in the `onload` attribute of the `` tag, but that's an absolute hack. You're also losing any previously declared `window.onload` function, and the code in the question is making a specific effort for that *not* to be the case. – Anthony Grist Sep 27 '13 at 14:36
  • What happens if the client's function (or for that matter, a different client using the same code) changes the name of it? – Qantas 94 Heavy Sep 27 '13 at 14:38