PDA

View Full Version : Can I do this in javascript? Involves converting...



StivenUSB
03-02-2007, 07:48 AM
I tried converting html to javascript using an online code converter, once the html converted to javascript, I saved the javascript output to a .js file. What I would like to do is have a single line in my html displaying the js content so that I can go in and change only this .js file when updating is needed. I expect the content to be displayed on multiple websites. If I update it from my server, I'd like it to change on all sites that the script would be on...

So what I did was saved the javascript output I received, after converting the html to javascript, to a .js file and I tried making the content appear on my regular page by doing something like this <script language="javascript" src="http://www.mydomain.com/FILENAME.js"></script> but it is definitely not working...

Is it possible to do something like this? If not, is there an alternative other than using an iFrame which I don't want to do...? The javascript code once it was converted from html is pasted below...

Any help is greatly appreciated,

Stiven USB


-----------------------------------------------------------------------

<script type="text/javascript" language="JavaScript">
<!--
document.writeln('<table width="380" border="1" bgcolor="#666666">');
document.writeln(' <'+'!--DWLayoutTable-->');
document.writeln(' <tr bgcolor="#000066"> ');
document.writeln(' <td colspan="3" valign="top"><table width="100&#37;" border="0" cellpadding="0" cellspacing="0" bgcolor="#666666">');
document.writeln(' <'+'!--DWLayoutTable-->');
document.writeln(' <tr> ');
document.writeln(' <td width="371" height="39" align="center" nowrap><a href="http://www.ultimatesportsbets.com"><img src="http://www.ultimatesportsbets.com/javabanner.gif" width="370" height="39" border="0"></a></td>');
document.writeln(' </tr>');
document.writeln(' </table></td>');
document.writeln(' </tr>');
document.writeln(' <tr> ');
document.writeln(' <td width="87" height="20" bgcolor="#000066"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong><u>Sport:</u></strong></font></td>');
document.writeln(' <td colspan="2" valign="top" bgcolor="#000066"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">NBA ');
document.writeln(' Basketball</font></strong></td>');
document.writeln(' </tr>');
document.writeln(' <tr> ');
document.writeln(' <td bgcolor="#000066"><u><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Match-up:</strong></font></u></td>');
document.writeln(' <td width="272" valign="top" bgcolor="#000066"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Orlando ');
document.writeln(' Magic (-7) @ Detroit Pistons</font></strong></td>');
document.writeln(' </tr>');
document.writeln(' <tr> ');
document.writeln(' <td bgcolor="#000066"><u><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Pick:</strong></font></u></td>');
document.writeln(' <td valign="top" bgcolor="#000066"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Detroit ');
document.writeln(' Pistons (+7)</font></strong></td>');
document.writeln(' </tr>');
document.writeln(' <tr> ');
document.writeln(' <td bgcolor="#000066"><u><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Record:</strong></font></u></td>');
document.writeln(' <td valign="top" bgcolor="#000066"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">11-3 ');
document.writeln(' ATS</font></strong></td>');
document.writeln(' </tr>');
document.writeln('</table>');
//-->
</script>

Twey
03-02-2007, 02:59 PM
Do not do this. The best way of achieving what you want is to use a server-side language. If you can't, use an <iframe>. <iframe>s are better-supported than Javascript, aren't commonly disabled, and also don't slow down the page load dramatically.

Blake
03-02-2007, 03:35 PM
Do not do this. The best way of achieving what you want is to use a server-side language. If you can't, use an <iframe>. <iframe>s are better-supported than Javascript, aren't commonly disabled, and also don't slow down the page load dramatically.

On top of that, it's a lot easier to do it with php. If you have, say, a header that you want in ever page, just put the html for the header in a file called header.inc, and in each page, add the line

<?php include("header.inc"); ?>

That's all it takes. It's faster, and you don't need to call a function to write every line.

I use that trick all the time.

StivenUSB
03-02-2007, 07:04 PM
So you are saying that all I would do is copy and paste my html and save it as header.inc? My apologies for being a bit oblivious to using php :-/...

Then if I want that content to show up in my page, or if I want to tell someone how to place my content on their own page, I would tell them to download and upload the file header.inc to their server, then paste the snippet "<?php include("header.inc"); ?>" wherever they want the content to appear?

If it is as simple as that then that's wonderful... My assumption however is that this snippet "<?php include("header.inc"); ?>" would be placed in the <head> section of my html and I would need further code in the <body> to make the content appear... no?

At any rate, please let me know as I really appreciate your help Blake... If anyone else has any input it is much appreciated.

Thank you,

StivenUSB

Blake
03-02-2007, 07:20 PM
No that's not quite it.

Any content you want to appear in multiple pages can go in a .inc file. You could call it whatever you want as long as it ends in .inc. Then, you put the include thing in the place where you want to the content to appear. Here's an example:

header.inc:



<html>
<head>
<title>Welcome to my web page!</title>
</head>
<body>


footer.inc



</body>
</html>


page1.php



<?php include("header.inc") ?>
This is page 1.
<?php include("footer.inc") ?>


page2.php



<?php include("header.inc") ?>
This is page 2.
<?php include("footer.inc") ?>


Now, if you open page1.php, the server will send the following to your browser:



<html>
<head>
<title>Welcome to my web page!</title>
</head>
<body>
This is page 1.
</body>
</html>


And if you open page2.php, the server will send the following to your browser:



<html>
<head>
<title>Welcome to my web page!</title>
</head>
<body>
This is page 2.
</body>
</html>


Any change you make to header.inc or footer.inc will now show up in both files.

Twey
03-02-2007, 08:10 PM
It doesn't even have to end in .inc, that's just a convention.

StivenUSB
03-02-2007, 10:56 PM
Well I guess I will just do it in html on its own page and then include it for myself or for any other person who would want the content in a nonscrollable iFrame...

One thing with these iframes though.. Are they search engine friendly? Is it beneficial to include the <noscript> tag or is that only for older browsers and for people that access your page from a pda for example..? My page is a sports related website and when it is redesigned, I will be getting a lot of my content via iframes, perhaps 2-3 per page at times. I am just wondering how this will effect my PR..

I have received great support from this forum thus far and thank you to everyone for your help.

StivenUSB

Twey
03-02-2007, 11:06 PM
One thing with these iframes though.. Are they search engine friendly?Not really, no. They're better than Javascript, though.
Is it beneficial to include the <noscript> tag or is that only for older browsers and for people that access your page from a pda for example..?Usually, yes, but I don't know what you'll be able to do with it in this case.
My page is a sports related website and when it is redesigned, I will be getting a lot of my content via iframes, perhaps 2-3 per page at times. I am just wondering how this will effect my PR..Badly. The only method that won't is server-side scripting. If you're thinking of hosting a big website (big enough to care about page rank), you should definitely invest money in hosting with server-side scripting support and time in learning to use it properly.