hide iframe url in HTML source code

2019-04-12 08:02发布

How to hide iframe url From HTML source code?

<iframe src="http://mysite.com" frameborder="0" scrolling="no" width="728" height="90"></iframe>

标签: iframe
3条回答
对你真心纯属浪费
2楼-- · 2019-04-12 08:34

There's no way to fully block source viewing. But there are a couple ways to disable right-clicking:

1) Javascript:

<script language="JavaScript">
<!--

var message="Your message goes here.";

function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
// -->

2) Add the following into your tag: oncontextmenu="return false"

reference https://forum.powweb.com/archive/index.php/t-36161.html

查看更多
3楼-- · 2019-04-12 08:38

You can use javascript to load the source, and it will not be visible in iframe url in page source code. For example with jQuery:

<script type="text/javascript">
$(document).ready(function(e) {
  $('iframe').attr('src','http://www.flickr.com/');
});
</script>

<body>
<iframe src="" />
</body>

Example here.

You can combine it with $.post to get the value serverside:

$.post('get-iframe-src.php', function(data) {
  $('iframe').attr('src',data);
});

You can even load iframe itself to some element like:

$.post('get-iframe.php', function(data) {
  $('#element_id').html(data);
});

etc. solutions are many, this is just one of.

查看更多
女痞
4楼-- · 2019-04-12 08:40

You can't. If the URL isn't in the HTML, how would the browser know where to get it?

One thing you could try is to obscure it to make it slightly harder for someone to find it. You could have the src attribute be blank and then when the document is ready fetch the URL value from the server in a separate AJAX request and update the iframe tag to include that value in the src.

This would be a fair amount of work, however, and wouldn't really accomplish anything. The only thing it would prevent is somebody finding it by viewing the page source. They can still look at the "current version" of the HTML in any web browser's debugging tools. (Right click on an element and inspect it, which is nearly ubiquitous at this point.) Or any other normal traffic-sniffing tools will see it plain as day.

Ultimately, if the web browser needs to know a piece of information, then that information needs to be visible on the client-side.

查看更多
登录 后发表回答