开发者

Prevent JavaScript inside Fancybox

Most results of searching for "prevent JavaScript inside Fancybox" results in folks lamenting that access to JavaScript functionality within Fancybox is limited. My problem is just the opposite.

My program is storing pages from the web for later display (this is for content that would otherwise change with time -- think news-stories without permalinks). The user is then able to search within the content of these stories for certain keywords (I do a full-text search against the content stripped of html using SQLite's FTS for now). If there is a match, a snippet is shown, and a link is provided that allows viewing the stored story in a Fancybox popup.

The problem is, when the stored story is retrieved from the database and viewed via ajax in Fancy开发者_开发技巧box, its embedded JavaScript tries to butt in, perhaps resize the page, or try to open popups, etc.

Two questions -- One, can I prevent any JavaScript from firing within a Fancybox window? Two, is there a better, more elegant way of accomplishing this? One way might be to convert the web page into a PDF, and then store that PDF. But that is more complicated, and it would break for long stories. We want to be able to view the historical story, even if it is not true fidelity to original as far as the looks are concerned.


You can start by stripping out <script> tags (on the server, of course).


Display the content in an <iframe>, preferably served from a different domain so that the browser enforces same-origin security policies. The scripts on the page will still run (which could be a good thing – perhaps some of these pages rely on scripts for some of their functionality), but your containing page will be safe from any interference by those scripts.

$.fancybox({
    href: '//content.example.com/id/nnnnn/',
    type: 'iframe'
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜