开发者

Have dynamic (as in changing/updated e.g, a blog page) links contained inside a div open in that same div

开发者 https://www.devze.com 2023-03-06 07:11 出处:网络
I currently have the below script that grabs the links inside the div (scrollbox) and as you can see it is set to have the links open in a new window. I need to have them open in the div they come fro

I currently have the below script that grabs the links inside the div (scrollbox) and as you can see it is set to have the links open in a new window. I need to have them open in the div they come from within the original page. Can I do this with this script? If not what should I be using?

function Init()
{
    // Grab the appropriate div
    theDiv = document.getElementById('scrollbox');
    // Grab all of the links inside the div
    links = theDiv.getElementsByTagName('a');
    // Loop through those links and attach the target attribute
    for (var i=0, len=links.length; i < len; i++) {
        // the _blank will make the link open in new window
        links[i].setAttribute('开发者_如何学运维target','_blank');
    }
}
window.onload = Init;

Thanks very much for the help!


If you want to load the pages the links refers to, but in the current page, you should consider using the <iframe> tag.

But maybe i don't understand fully what you need


Look into JQuery's load function

Something like this should work:

<div id="webpageContainer"></div>

$( "#link" ).click( function()
{
    $( "#webpageContainer" ).load( $(this).attr( 'href' ));
});
0

精彩评论

暂无评论...
验证码 换一张
取 消