Alternatives to Iframe

六月ゝ 毕业季﹏ 提交于 2019-12-12 19:07:15

问题


I have been developing a service that allows users to insert information from my database onto their sites by using iframes. The only problem was that the iframe needs to be resizeable and this is one of the biggest problems with iframes as most people already know, aswell as the fact I can access objects on the parent page from within the iframe and vice versa.

I have thought of making an asp.net web servie to server up the HTML and access it by using a get request. However this also has a problem since these request can only be made from the same domain?

What I need to know is the best way to retrieve a small piece of HTML containing customer reviews from server and display it on their page using some sort of AJAX.

Thanks


回答1:


if your users can add a < script > line to their site pointing to code on your site, you can fairly easily offer a mechanism to build a floating (and resizable) DIV on their page that you jquery.load() with content from your site ...

example: "To use my service on your site, add the following line to your < head >"

<script type='text/javascript' src='http://mysite.com/scripts/dataget.js /> 

then add a link or button anywhere and give it a class 'get-date-from-mysite'

< input type='button' value='Click to see the data' class='get-data-from-mysite' />

--

Then in that script you do (something like):

$(function() {
    $('.get-data-from-mysite').click(function() {
        $('body').append("<div id='mydiv' 'style=position:absolute; z-index:999; left:                 ...

        $('#mydiv').load(' .... // url that sends html for content
    });
   ...etc

resize-able div stuff needs to be added too




回答2:


I think the jQuery library might be what you need - specifically, look into jQuery Ajax.




回答3:


Following on what Scott Evernden is explaining, you can add a <script> tag such as:

<script id="my_script_tag" type='text/javascript' src='http://mysite.com/scripts/dataget.js' />

Inside dataget.js you can simply reference the script tag itself by using its "id" (document.getElementById("my_script_tag");) and replace it (insertBefore()) with relevant data.

To get the data from your server you can use JSONP (lots of stuff on SO as well), which is an ajax technique for cross-domain communication.



来源:https://stackoverflow.com/questions/574214/alternatives-to-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!