I am trying to load a div from another domain and display it on my site. An <iframe> will not work as the content is dynamically sized and I don't wish to render the entire page, just the content of <div id="content-article">
I have attempted to follow the guide from: http://frinity.blogspot.com/2008/06/load-remote-content-into-div-element.html however after reading the comments it appears to only work for external pages on the same domain.
I don't really care how it is done; php, jquery, ajax or what have you I just don't want to upload the same content to two different domains.
Is there any way to do this?
You can't when it should fetch it from external URL. Perhaps you can create a proxy or so and do a jquery.get?
You could use PHP's DomDocument to parse the HTML of the page that has the div and extract the div you want and then put it into your own content.
What is the URL with the div you want to grab? (Maybe we could write some code to help you pull it out.)
Related
for example: you created a website and in that website you want to create a login page using php. Do you use the css file that you design your website with, to design login page?
You can use a single CSS page to style your whole website if you want to . You will just have to make sure you load in every html file that you load in the browser.
I would suggest splitting this up css file into parts if you expect your application to grow bigger.
PHP actually runs on the server and it renders html (usually).
So if the template you're rendering with php has the same css file included you could use the same css for both pages.
Now for your needs, the login page has possibly some css that your other pages don't need. I would suggest creating a common.css file with everything that both pages will have and another with the login page specific styles.
I hope that's what your looking for.
I need to display content that was posted from the previous page within iframe. Is it possible?
The content will have HTML tags.
The reason why I need iframe, because it will also have reference to CSS. If I just echo it on page, then it will make problems with CSS style of the main webpage. The only sollution I have found is to use iframe.
Why not just correct your CSS?
FWIW, I don't think you are able to POST data to anything inside an iFrame, especially if you don't have control over the iFrame content.
Iframes link to a URL.
So if you can save the post data into a file on your server and then use ajax or refresh the page to inject the url to that file on the iframe, then you will be sorted.
My homepage (index.php) is generated dynamicly by PHP, so it takes about 1s till the the page is delivered to the user.
Because my css and js script is in the header of (index.php), after this 1s the css and js will start to download.
Is there some general way of preloading this js and css files?
My aproach would be to delete all content of index.php, include just <'head> with my css and js file, and then do some js to load the whole indexOriginal.php (with the dynamic content generated on my server by PHP), so this should enable the user to download the css, js in parallel of indexOriginal.php.
Is this the right aproach?
The approach you suggested could work. You also might consider altering your PHP script to hurriedly deliver the first part of the page (<html> down through <body>) before it starts getting the rest of the page together (see http://php.net/manual/en/function.flush.php).
Your page full generated by backend and sended to user only after php script end its work.
You could, for example, create page like.
<html><head><script></script></head><body></body></html>
In <script></script> load, for example, JQuery and do something like
$(document).ready($('body').load('/path/to/your/script.php'))
But I really thing this wouldn't be a good practice. Also I don't think that Google would parse your site content with this solution.
I think you should look better about your JS (compress, gzip, split to many files and upload them from different CDNs, move everything to $().ready, etc.)
My recommendation would be to have your initial PHP script JUST deliver the CSS and JS tags. Once those are loaded, use the JavaScript to make an AJAX call that gets the rest of the page then displays it. Or you can build the page in the JavaScript (which would allow you to use loading icons and the like to give a better indicator to the user that "the page is coming")
I two website abc.com content div with id 'abc' and another website def.com. content div with id 'def'. The Qns is how can I display content of div having id='abc' into div id='def'.
Well you need to scrape content of abc.com, then search dom element to find div "abc", fetch its content and put it in def div of another site.
for scraping use http://simplehtmldom.sourceforge.net/
That can not be possible , reason is to read content you need to call some ajax request. And ajax never works between cross domain.
The thing you are trying to do is called webpage scrapping. You can not do it using client side Javascript alone as it gives cross-domain error. But you can use node.js - server side javascript.
http://net.tutsplus.com/tutorials/javascript-ajax/web-scraping-with-node-js/
I am currently trying to stream the content located on http://store.kenstanton.net/Default.asp the five images located just above the featured videos
and stream it to http://www.kenstanton.net to the content (currently the same atm however I would like to be able to update one webpage and have the following update as well) above the featured videos on that page.
I'm currently trying to use an ajaxpagefetch script if thats the appropriate route our should I curl it and then parse?
AJAX is probably the way to go - you might want to look at jQuery manual for .load(). In your case it'd be something like:
$('#result').load('http://store.kenstanton.net/Default.asp .v65-productDisplay');
But of course there might be some styling issues as well as AJAX security restrictions (of those I'm not sure, but writing simple redirector should do the trick in such case)