views:

115

answers:

2

This is a great big mess...

I know I could use an iframe, but the problem there is that there are some cross-site limitations that wind up botching what I'm trying to do. Namely, the source content is a fixed height div that allows scrolling, but without the scrollbar. If I load that up in an iframe, it won't have the same effect. It either insists on having a scrollbar, or it doesn't scroll at all. I've been trying to find a way around this, but the destination server doesn't have php available, so I'm flat-out stuck on how to do this...

On the source server, I tried writing all of the content to a php variable like this:

<script type="text/javascript">
var mycontent = '<?php print $content; ?>';
</script>

and then calling that variable in my test.js file and when I use an alert, I get the text (also on the source server), like this:

var content = mycontent;
alert(content);

It works, but, not from the destination server. So, on the destination server, if I use:

 <script src="http://mysite.com/test.js"&gt;&lt;/script&gt;

And try to use:

<script type="text/javascript">document.write('content');</script>

It doesn't print anything out... I'm assuming because of cross-site limitations? I'm desperate for a workaround... Can anyone help out?

A: 

It should be perfectly well possible to do a

<script type="text/javascript" src="http://mysite.com/test.js"&gt;&lt;/script&gt;

and in the Javascript, without <script type...., do

document.write('blah');
document.write('blah');
document.write('blah');
document.write('blah');
document.write('blah');

this will work fine across domains. I think your problem is that you embed <script> tags into the js file, which is wrong. Such things will pop up as syntax errors in Firefox's Error Console, an invaluable tool when developing JavaScript.

There's a downside to this approach by the way: If your target server serving the JS is down, the rendering of the document that embeds the script will be delayed.

Pekka
except that you probably want the `content` variable, not the `'content'` literal string.
nickf
The js doesn't have <script type>. It's just:$(document).ready(function() { var content = mycontent; document.write(content);});All I get is: [object Window]
andy787899
Jquery code? In a remote script? Together with document.write? I doubt that is going to work. You should have mentioned that earlier. Can you post your full code?
Pekka
A: 

Make a server-side XHR request, grab the content, and include it when your page is served-up.

Diodeus