Compartir a través de


Null protocol return values

Windows Internet Explorer 9 now follows HTML5 guidelines when handling JavaScript protocols that return "null".

HTML5 states that if a script running within a JavaScript protocol returns "null", the browser must treat the URL as if it has returned HTTP 204 No Content, which must not contain a response body.

Consider this example:

<!DOCTYPE html>
<html>
<head>      
</head>
<body>
   <div id="ad_content">
      <iframe src="javascript:document.write('...'); return null;" />
   // document.write is meant to create the contents of the iframe
   </div>
</body>
</html>

Since the JavaScript executed as part of the JavaScript protocol (javascript:) returns "null", Internet Explorer 9 and other browsers that comply with this part of HTML5 treat the URL as if it returned HTTP 204 No Content so the iframe is empty, regardless of what other JavaScript ran in the JavaScript protocol.