Unable to insert object in js popup

I have this code:

<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='800' height='470' id='Gen5Core' align='middle'><param name='allowScriptAccess' value='always'/><param name='allowFullScreen' value='true'/><param name='movie' value='http://h71016.www7.hp.com/html/interactive/_core/Gen5Core.swf?corePath=http://h71016.www7.hp.com/html/interactive/_core/&serverName=http://h71016.www7.hp.com/html/interactive/p1102w/'/><param name='quality' value='high'/><param name='bgcolor' value='#333333'/><embed src='http://h71016.www7.hp.com/html/interactive/_core/Gen5Core.swf?corePath=http://h71016.www7.hp.com/html/interactive/_core/&serverName=http://h71016.www7.hp.com/html/interactive/p1102w/' quality='high' bgcolor='#333333' width='800' height='470' name='Gen5Core' align='middle' allowScriptAccess='always' allowFullScreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object> 

It works great if I put it directly on the page.

But I want to enable it on the fly in a popup, so I wrote this function:

 <script type="text/javascript"> $(document).ready(function () { $('.newWindow').click(function (event) { var termWin = window.open('', '', 'width=600,location=0,toolbar=0,resizable=1,height=400,menubar=0,scrollbars=1'); termWin.document.write('<html><head><title>TITLE</title><body><div> <object classid=\'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\' width=\'800\' height=\'470\' id=\'Gen5Core\' align=\'middle\'><param name=\'allowScriptAccess\' value=\'always\'/><param name=\'allowFullScreen\' value=\'true\'/><param name=\'movie\' value=\'http://h71016.www7.hp.com/html/interactive/_core/Gen5Core.swf?corePath=http://h71016.www7.hp.com/html/interactive/_core/&serverName=http://h71016.www7.hp.com/html/interactive/p1102w/\'/><param name=\'quality\' value=\'high\'/><param name=\'bgcolor\' value=\'#333333\'/><embed src=\'http://h71016.www7.hp.com/html/interactive/_core/Gen5Core.swf?corePath=http://h71016.www7.hp.com/html/interactive/_core/&serverName=http://h71016.www7.hp.com/html/interactive/p1102w/\' quality=\'high\' bgcolor=\'#333333\' width=\'800\' height=\'470\' name=\'Gen5Core\' align=\'middle\' allowScriptAccess=\'always\' allowFullScreen=\'true\' type=\'application/x-shockwave-flash\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\'></embed></object> </div></body></html>'); termWin.document.close(); termWin.focus(); }); }); </script> 

which will be opened when the user clicks on the link with the newWindow class.

  <a href="#" class="newWindow"> <img src="@Url.Content("~/Content/Images/icon_demo_black.gif")" /> </a> 

I have one problem:

  • in Chrome, the popup is empty, so the embedded object does not work (but I see how to verify that the code was successfully placed in the html source).

Can you give a helping hand?

+4
source share
1 answer

Chrome runs the rest of javascript before the window is ready to accept the entry. I don’t have much time to check it right now on all browsers, but it worked on Chrome 18 and IE9 http://jsfiddle.net/fordlover49/GP2Gz/

Basically, we just do setTimeout with a fixed delay of 100 ms to give the browser time to get the window ready.

Please note that the original answer (which was the same director) added an extra check for the readyState document, but readyState is not consistent between browsers (for example, Firefox 9 has a β€œuninitialized” window state as long as you fill in the URL or what something else on the page).

I tested this and it seems to work fine on IE8 and IE9, Firefox 3.6.8 and 9, Chrome 17 and 18

 $(document).ready(function() { var termWin; function writeWindow() { termWin.document.write('<html><head><title>TITLE</title><body><div> <object classid=\'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\' codebase=\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\' width=\'800\' height=\'470\' id=\'Gen5Core\' align=\'middle\'><param name=\'allowScriptAccess\' value=\'always\'/><param name=\'allowFullScreen\' value=\'true\'/><param name=\'movie\' value=\'http://h71016.www7.hp.com/html/interactive/_core/Gen5Core.swf?corePath=http://h71016.www7.hp.com/html/interactive/_core/&serverName=http://h71016.www7.hp.com/html/interactive/p1102w/\'/><param name=\'quality\' value=\'high\'/><param name=\'bgcolor\' value=\'#333333\'/><embed src=\'http://h71016.www7.hp.com/html/interactive/_core/Gen5Core.swf?corePath=http://h71016.www7.hp.com/html/interactive/_core/&serverName=http://h71016.www7.hp.com/html/interactive/p1102w/\' quality=\'high\' bgcolor=\'#333333\' width=\'800\' height=\'470\' name=\'Gen5Core\' align=\'middle\' allowScriptAccess=\'always\' allowFullScreen=\'true\' type=\'application/x-shockwave-flash\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\'></embed></object> </div></body></html>'); termWin.document.close(); termWin.focus(); } $('.newWindow').click(function(event) { termWin = window.open('', '', 'width=600,location=0,toolbar=0,resizable=1,height=500,width=840,menubar=0,scrollbars=1'); setTimeout(writeWindow, 100) }); }); 
+1
source

Source: https://habr.com/ru/post/1392746/


All Articles