david77 Posted May 20, 2012 Share Posted May 20, 2012 Can someone please explain this to me from http://www.w3schools...ntentwindow.asp What is x?What is y?What does "if (y.document)y=y.document;" mean? function changeStyle(){var x=document.getElementById("myframe");var y=(x.contentWindow || x.contentDocument);if (y.document)y=y.document;y.body.style.backgroundColor="#0000ff";} fnlights() is called by clicking on the L button of my 'cpu' on http://homepage.ntlw...andtraffic2.htm function fnlights() {var lite, attrgoslow=false;var doc=top.document.getElementById("trafficdoc");var obj=(doc.contentWindow || doc.contentDocument);if (obj.document) obj=obj.document;lite = obj.getElementById("x1red");attr = lite.getAttribute("fill");if (attr == "red") { lite.setAttribute("fill", "black"); }else { lite.setAttribute("fill", "red"); }} This should toggle the top left red light. It works on Opera and Firefox but not on IE8 or Chrome browsers. Advice much appreciated, thanks Bring back Pascal, all is forgiven! Link to comment Share on other sites More sharing options...
dsonesuk Posted May 20, 2012 Share Posted May 20, 2012 (edited) IE OR old versions of IE (not sure about IE9 if this still applies) uses a different method of accessing iframe as in .contentWindow, while other better browsers use the other. only .contentWindow will use '.document' as in .contentWindow.document To determine which method to use for specific browser we find out which one it recognises var obj=(doc.contentWindow || doc.contentDocument); //use method that browser will support if (obj.document) // does the method you support use .document, if yes the selected method will apply .documentobj=obj.document; Edit: instead of 'top' try 'parent' instead var doc=parent.document.getElementById("trafficdoc"); Edited May 20, 2012 by dsonesuk 1 Link to comment Share on other sites More sharing options...
david77 Posted May 20, 2012 Author Share Posted May 20, 2012 Thanks dsonesuk - parent works with Chrome, Opera, and Firefox. IE8 reports Access is denied. line 794, column 0. 794 is the next blank line after the closing bracket of fnlights() Link to comment Share on other sites More sharing options...
dsonesuk Posted May 20, 2012 Share Posted May 20, 2012 Does IE8 even support svg? I've never used svg, and knowing how bad IE support for new features such as these, makes me wonder? it took several year for IE to match what better browser support with IE9! 1 Link to comment Share on other sites More sharing options...
david77 Posted May 20, 2012 Author Share Posted May 20, 2012 I fear that you are right, dsonesuk. IE8 displays the CPU and Traffic light images, but it looks as tho I can't get the cpu to control the lights. I will detect IE8 and show an alert: "Sorry - my prog doesn't display with that browser. Try Opera, Firefox, or Chrome." Thanks again. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 20, 2012 Share Posted May 20, 2012 http://w3schools.com/svg/svg_intro.asp Viewing SVG FilesFirefox, Internet Explorer 9, Google Chrome, Opera, and Safari support SVG.IE8 and earlier needs a plug-in - which is available for free, like Adobe SVG Viewer. Link to comment Share on other sites More sharing options...
david77 Posted May 20, 2012 Author Share Posted May 20, 2012 I have downloaded that SVG viewer. IE8 displays the images but I can't get fnlights() in the cpu to toggle the traffic light. Thanks again. Link to comment Share on other sites More sharing options...
david77 Posted May 20, 2012 Author Share Posted May 20, 2012 My next problem is getting the cpu to write to the traffic lights. When I was getting the traffic lights to work, I had test buttons to call function fnportone(opcount) or fnporttwo(opcount) to change the lights. If you click on N to load a new prog, a child.htm page comes up with a preloaded simple prog. Clicking on Paste to cpu on the child page calls window.opener.storeprog(s); in the child page to store the prog in CPU memory. I was hoping to do something like that from the cpu to call the traffic functions. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 20, 2012 Share Posted May 20, 2012 You can't use server script (php, asp/.net) to include instead of iframe?? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now