dom - document.location.href got javascript:window["contents"] -


the return value of document.location.href become javascript:window["contents"] sometimes. when happened? how avoid it?

i found out code placed in iframe without src url.

<iframe id="google_ads_iframe_/21202031/ltn-000-03-home-120x600-display_0" name="google_ads_iframe_/21202031/ltn-000-03-home-120x600-display_0" width="120" height="600" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" src="javascript:&quot;<html><body style='background:transparent'></body></html>&quot;" style="border: 0px; vertical-align: bottom;"></iframe> 

as have suspected, indeed has (i)frames , more specifically, way scripts/libraries work frames.

it a technique avoid referenceerror (in ie) in cases when loading external javascript (that loaded asynchronous) holds/provides variables/objects used in frame's inline-script-source.

to quote relevant part article called 'inject content new iframe' :

instead of using document.open/write/close use following approach:

iframe.contentwindow.contents = content; iframe.src = 'javascript:window["contents"]'; 

first, assign dynamic content variable on iframe’s window object. invoke via javascript: scheme. not renders html properly, loads , executes scripts in desired order.

this in-line similar answer on so.

hope helps!


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -