html - My Javascript function is influenced by another JS function already defined -


i have html/css/js page css , js functions (not created myself) defined within <head> tag. page displaying title @ beginning , beneath there 4 tabs defined css style working dynamically using js. wanted add own js function, should loading onload:

<script type="text/javascript">      function replacesrc()     {         document.getelementbyid("ytplayer").src = "blablabla";     }     window.onload = replacesrc; </script> 

however, when running page, content produced css/js disappears (just title of page remains).

so questions are:

  1. can problem there 1 js function defined loading onload?
  2. if so, how handle it?

i have tried put function declaration different places within html, removing tag , putting tag, still not work.

when (or somebody's else) use window.onload = somefunction, remove precedently attached load event handler.

you should use addeventlistener :

window.addeventlistener('load', replacesrc); 

if want compatible old ie browsers, use

if (window.addeventlistener){   window.addeventlistener('load', replacesrc, false); } else if (window.attachevent) {   window.attachevent('onload', replacesrc); } 

edit : comment, seems you're trying change src of iframe served server origin. can't due same origin policy. see example related question : change src iframe cross-domain


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -