0
I’m creating a page that will simulate a website in the mobile version.
After filling in the URL field, the site will appear in an "Iframe".
The problem is that when I enter the URL into the field, some sites work and others don’t. I am passing the value of the field via "attr". Has anyone ever been through this or would you know how to help me? Look at the code:
function simula(){
var x = document.getElementById('campo1').value;
$('iframe').attr('src', x);
}
#campo1{width: 300px; padding: 10px;}
.bt{padding: 10px 40px; background: #000; color: #fff; border: 0px; cursor: pointer;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p align="center">
<input type="text" name="campo1" id="campo1" placeholder="Inserir URL"><br><br>
<button class="bt" onclick="simula()">TESTAR</button>
<br><br><br>
<iframe name="Iframe" class="frame" width="800" height="400"></iframe>
</p>
Hello @Reset, Welcome to Sopt, before you start a look at our [Tour]. -- It is only worth you add the following information, Tested websites and In which it worked, but I can tell you that it seems to me that you are having problems with the response header
X-Frame-Options
and not with your code, here at Sopt, there are already answers talking about it, I’ll put one here as possible duplicated =D– Icaro Martins
Dear, not all sites accept to be loaded in iframes.
– Sam