简体   繁体   中英

Using jQuery to load a page that require javascript in a div

I created a simple function to append floating resizable content to a page:

function CreateFloatingWindow(id) {
        var win = document.createElement('div');
        $(win).attr('id', id);
        $(win).height(100).width(300).css('background-color', 'red');
        $(win).resizable().draggable();
        $(win).appendTo($('body'));
        $(win).load('http://www.fantasy-mmorpg.com/fowiki/#1419~2');
}

CreateFloatingWindow('first');

The code works all right, except when the loaded page have some kind of javascript inside, in this case the result is a 'Please activate javascript' message like this

I think the message is handled by the target page itself, but I don't have access to its source.

Is there a way to make the target page understand that I have my javascript enabled even if it is loaded in a div via jQuery?

NB the above code requires jQuery and jQuery-UI to run properly.

I've been digging through and a couple of things to note:

Firstly this clause within the jQuery .load() docs which might shed some light:

Script Execution

When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed . An example of both cases can be seen below:

Here, any JavaScript loaded into #a as a part of the document will successfully execute.

1 $('#a').load('article.html');

However, in the following case, script blocks in the document being loaded into #b are stripped out and not executed:

1 $('#b').load('article.html #target');

Check against different browsers for the message 'Please Activate JavaScript', which I'm not sure if this is at Script level or Browser level. But I'm quite sure the " Please Enabled JavaScript " is probably the HTML Fallback <noscript> - If it's not executing any JavaScript at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM