admin管理员组

文章数量:1426458

this script load content using an IFRAME is there any way to just load the content from the page but not as iframe?

something like

$("#content2").load($(this).attr("page"));

But i can't seem to make it work on the above script.

<script type="text/javascript">
function loadURL(u) { 
document.getElementById("web-panel").innerHTML = '<iframe src="' + u + '"
width="100%" height="100%" border="0"></iframe>';}</script>

<select name="mydropdown" id="url" onchange="loadURL(this.value);">
<option value=".php?3">opt3</option>
<option value=".php?2">opt2</option>
<option value=".php?1">opt1</option>
</select>

<div id="web-panel"></div>

this script load content using an IFRAME is there any way to just load the content from the page but not as iframe?

something like

$("#content2").load($(this).attr("page"));

But i can't seem to make it work on the above script.

<script type="text/javascript">
function loadURL(u) { 
document.getElementById("web-panel").innerHTML = '<iframe src="' + u + '"
width="100%" height="100%" border="0"></iframe>';}</script>

<select name="mydropdown" id="url" onchange="loadURL(this.value);">
<option value="http://123./opt.php?3">opt3</option>
<option value="http://123./opt.php?2">opt2</option>
<option value="http://123./opt.php?1">opt1</option>
</select>

<div id="web-panel"></div>
Share Improve this question edited Dec 20, 2014 at 2:40 user663031 asked Dec 20, 2014 at 2:07 paisapimppaisapimp 1151 gold badge2 silver badges9 bronze badges 1
  • Are you taking about Ajax? You can find a basic example here: w3schools./ajax/default.asp and more information here: api.jquery./jquery.ajax – erikvimz Commented Dec 20, 2014 at 2:30
Add a ment  | 

2 Answers 2

Reset to default 1

To load content of an URL into a div without using the IFrame, you could try using jQuery Ajax approach: (the first line is important, as it includes the jQuery framework)

<script type="text/javascript" src="https://code.jquery./jquery-1.11.2.min.js"></script>
<script type="text/javascript">
function loadURL(u) { 
    $.ajax({
        url: u,
        cache: false
    }).done(function(data) {
        $("#web-panel").html(data);
    });
}
</script>

<select name="mydropdown" id="url" onchange="loadURL(this.value);">
<option value="http://123./opt.php?3">opt3</option>
<option value="http://123./opt.php?2">opt2</option>
<option value="http://123./opt.php?1">opt1</option>
</select>

<div id="web-panel"></div>

Looks like you have JavaScript syntax error.

Change the JS part to look like this:

function loadURL(u) { 
    document.getElementById("web-panel").innerHTML = '<iframe src="' + u +
    '" width="100%" height="100%" border="0"></iframe>';
}

本文标签: javascriptLoad URL into a divStack Overflow