iFrame src something other than javascript:false but same effect

可紊 提交于 2020-01-04 04:05:14

问题


Is there any other way to write javascript:false that is more pleasant?

I'm building a print functionality for an intranet app (for IE6) and I make the printed page using an iframe:

$('body').append('<iframe id="printIFrame" src="javascript:false"></iframe>');
$("#printIFrame").attr('style','position:absolute;left:-500px;top:-500px;');

Without having javascript:false in the src, I'll get the "This page contains both secure and nonsecure items" popup when I create it. However the downside of this is that "javascript:false" gets printed as the title on the bottom left of each page (instead of about:blank or something more useful).

Is there some kind of javascript technique that I can write javascript:false but in cleaner terms? I tried something like this

var PrintOut = false;
$('body').append('<iframe id="printIFrame" src="PrintOut"></iframe>');

But I couldn't get that working. Any other ideas?


回答1:


I think you should use a "/blank.do" or something from the same server (or origin, rather) as (temporary?) src for your iframe. Then you should not get the "insecure" stuff.
Why do you want/need it to be done by javascript?




回答2:


How about an existing, but empty, resource using the same protocol?

<iframe id="printIFrame" src="https://example.com/empty.html"></iframe>

You could, to make it perfect, even have empty.html send a 204 No Content header to signify it's empty. (Info here)




回答3:


In order to avoid unwanted requests you have to use <iframe src="about:blank"></iframe>



来源:https://stackoverflow.com/questions/2503648/iframe-src-something-other-than-javascriptfalse-but-same-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!