is it possible to copy a div from a site to another? Managing many websites I need to copy some static portions of code (e.g. a common footer) without having to go on every website and change it. I was looking to use jQuery, I know about the .clone() but I don't know how to make it work from a site to another
Asked
Active
Viewed 2,838 times
1
-
use an iFrame to show that div, or store it server side and ajax it – Feb 24 '15 at 14:30
-
@Space Many thanks, I didn't know that tag. But it doesn't work as I wished. Is there a way to copy only the code instead of having the frame that shows the original page? – tabris963 Feb 24 '15 at 14:40
1 Answers
2
I was surfing around looking for an answer and found this code. If you can't use an Iframe.
As an alternative, you could just use a simple and use the jQuery "load" function to load the whole page and pluck out just the section you want:
$('#target-div').load('http://www.mywebsite.com/portfolio.php #portfolio-sports');
There may be other things you need to do, and a significant difference is that the content will become part of the main page instead of being segregated into a separate window.
-
-
It wasn't working so I tried to allow CORS but for some reason I fail... Isn't there another way to do this without allowing CORS? – tabris963 Feb 25 '15 at 12:05
-
What was your exception when you added CORS what was the error. Which server did you set CORS on the one you were taking it from or the one you were receiving it from. I'm pretty sure you'll need CORS or you're browser will block it for security reason's thinking someone is trying to XSS you – Feb 25 '15 at 15:16
-
The only other way is to have you're other server expose an Ajax call that will return the div, but you'll probably still need cors for that – Feb 25 '15 at 15:17
-
1
-
is this possible in wordpress? If so, where to put the script? in functions.php? – chikitin Dec 04 '20 at 23:42