PDA

View Full Version : scr not working?



ojsimon
10-12-2008, 06:47 PM
Hi
this javascript is generated by my code

document.writeln('<head><style>a{color: white; font-size:10px}a:visited{color: white; font-size: 10px;}</style></head><table><tr><tr BACKGROUND="http://localhost:8888/sitewidget/app/webroot/img/border.png"><th><font face="Verdana, Arial" size="4" color="white">Widget</font></th></tr><tr><td><style type="text/css"><!--#frame1 { width: 400px; height: 200px; border: none; background: white;}--></style><iframe src="/sitewidget/index.php/widget/show/aHR0cDovL3d3dy5iYmMuY28udWsvbG9uZG9uL25ld3Mv/156" name="frame1" id="frame1" scrolling="auto" frameborder="0"></iframe>');</td><tr><tr BACKGROUND="http://localhost:8888/sitewidget/app/webroot/img/border.png"><th><font face="Verdana, Arial" size="20px" color="white" vlink="white"><a href="/sitewidget/index.php/grab/check/aHR0cDovL3d3dy5iYmMuY28udWsvbG9uZG9uL25ld3Mv/156" target="_blank">Get this widget</a></font> <font face="Verdana, Arial" size="2px" color="white"> |</font> <font face="Verdana, Arial" size="20px" color="white" vlink="white"><a href="http://www.websnips.com" target="_blank">Make a widget out of any site</a></font></th></tr></tr></table>'<!-- 0.1254s -->

I am trying to run it like this

<html>
<SCRIPT LANGUAGE="JavaScript" SRC="js.html">
</SCRIPT>
</html>

I do not know why it is not running as an external file when it is running when you run the file directly?

Thanks

jscheuer1
10-12-2008, 09:26 PM
I don't think you have given us enough information, perhaps you have though. You have a mismatch between the tag used:



<SCRIPT LANGUAGE="JavaScript" SRC="js.html">
</SCRIPT>

and acceptable attributes for it in modern browsers, as well as a problem in that, even if the page js.html were to be evaluated as an HTML page with javascript on it (which might not even be possible), the result might not be as expected.

For the first part, the correct attribute to use with a script tag is ordinarily:


<script type="text/javascript" src="whatever.whatever"></script>

Due to server configuration there may be limits on what that second 'whatever' can be, it would have to be a file type that can be served as text/javascript on that server.

Now you might be able to get away with:


<script type="text/javascript" src="js.html"></script>

or:


<script type="text/html" src="js.html"></script>

But I doubt it. A lot would depend upon the server and upon just exactly what is in the js.html file. Also, browsers might be inconsistent in how they would view either approach.

However, say you are using PHP to create the external script file, if once created, it is valid javascript and the external file has the .php extension, you could do:


<script type="text/javascript" src="js.php"></script>

Similarly, if using asp to create the file, just use the .asp extension.

If it is all just strictly workable javascript in the external file, rename it to js.js and use:


<script type="text/javascript" src="js.js"></script>

If you want more help, please tell us how this external (script) file is created, and:

Please post a link to the page on your site that contains the problematic code so we can check it out.

ojsimon
10-13-2008, 04:26 PM
this external js is generated by a php script, previously it was generating html content however i have been trying to edit it to be of js nature, hence my problem. I am no expert with js so how can i make the original js file i sent you valid? so that it will work as an src?

Thanks

jscheuer1
10-13-2008, 07:20 PM
OK, I think I've got what you're doing. This much appears to be valid javascript writing (if not valid HTML, at least workable HTML):


document.writeln('<head><style>a{color: white; font-size:10px}a:visited{color: white; font-size: 10px;}</style></head><table><tr><tr BACKGROUND="http://localhost:8888/sitewidget/app/webroot/img/border.png"><th><font face="Verdana, Arial" size="4" color="white">Widget</font></th></tr><tr><td><style type="text/css"><!--#frame1 { width: 400px; height: 200px; border: none; background: white;}--></style><iframe src="/sitewidget/index.php/widget/show/aHR0cDovL3d3dy5iYmMuY28udWsvbG9uZG9uL25ld3Mv/156" name="frame1" id="frame1" scrolling="auto" frameborder="0"></iframe>');

If you added:


document.writeln('

right after that, and at the very end changed:


</table>'<!-- 0.1254s -->

to:


</table>\'<!-- 0.1254s -->');

or (probably what you are really after):


</table><!-- 0.1254s -->');

name the file js.php, and use:


<script type="text/javascript" src="js.php"></script>

on the page where you want it to do its work, things should work out, but there might be issues with the HTML code being written out in two parts.

However, if there is any way you could just generate the content 100% via PHP, that would be better, and the file could be used as an include instead of as an external script.