javascript - IE - entire page redirects if iframe src is set with bad URL -


the code below shows problem. creates simple iframe.

on browsers besides ie if url set http:[4 slashes] test.com instead of http:[two slashes] test.com iframe show error. on ie parent page redirects error page.

i'm using iframe in widget in other people's website , can cause lot of damage in case of error. question how can avoided if src url bad error remain in iframe , not cause entire page redirect.

to check can copy code jsfiddle.net , run.

popup = window.document.createelement('div'); popup_html="<div style='width:300px;height:300px; ' >"; popup_html+=" <iframe src='http:////www.test.com' width='300' height='300' frameborder='0' ></iframe>"; popup_html+=" </div>"; popup.innerhtml=popup_html; //cbar_popup.style.visibility='visible'; window.document.body.appendchild(popup); 

you try clean url , attempt popup stuff if url valid:

var url = 'http:////stackoverflow.com/questions/16076720/ie-entire-page-redirects-if-iframe-src-is-set-with-bad-url'; var result = /^(?:(?:http[s]?:\/{2,4})?(?:www\.)?)?([\w-_]+)\.([\w\.]+)([\/\?\w-_\=\"]*)/.exec(url);  if(result){     url = 'http://'+result[1]+'.'+result[2]+result[3];     console.log(url);     // popup stuff here cleaned url } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -