By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,797 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,797 IT Pros & Developers. It's quick & easy.

Script will load but not through SRC

P: 59
Hi
this javascript is generated by my code
Expand|Select|Wrap|Line Numbers
  1. 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
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <SCRIPT LANGUAGE="JavaScript" SRC="js.html">
  3. </SCRIPT>
  4. </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
Oct 12 '08 #1
Share this Question
Share on Google+
12 Replies


acoder
Expert Mod 15k+
P: 16,027
The src needs to be for a JavaScript file, not an HTML one.

The attribute language is deprecated - set the type attribute instead to "text/javascript".

The HTML document should have a body and a valid doctype.

Not all of these should be the cause, but it's good practice anyway.
Oct 12 '08 #2

P: 59
The src needs to be for a JavaScript file, not an HTML one.

The attribute language is deprecated - set the type attribute instead to "text/javascript".

The HTML document should have a body and a valid doctype.

Not all of these should be the cause, but it's good practice anyway.
I thought the file i am trying to src was javascript, how do i change this to javascript?

Thanks
Oct 12 '08 #3

acoder
Expert Mod 15k+
P: 16,027
Change the extension to .js.

The script shouldn't really be writing the head content too. Try putting the head section in the HTML page and use the file to write the body content.
Oct 12 '08 #4

P: 93
In the header tag of the html file include this peice of code


Expand|Select|Wrap|Line Numbers
  1. <head><script type="text/javascript"
  2.     src="Relative path where your  file is located from the current directory"></script></head>
Now change the extension properly from .html to .js be carefull while changing the extension sometimes in windows if you will change the extension like in this case the most generic error is, it will show the file.js on screen but actually it will be file.js.html.
Oct 13 '08 #5

P: 59
In the header tag of the html file include this peice of code


Expand|Select|Wrap|Line Numbers
  1. <head><script type="text/javascript"
  2.     src="Relative path where your  file is located from the current directory"></script></head>
Now change the extension properly from .html to .js be carefull while changing the extension sometimes in windows if you will change the extension like in this case the most generic error is, it will show the file.js on screen but actually it will be file.js.html.
Thanks, the only problem with this is that it is infact an automated html page i changed the parameters to make it js. Also i was only using the path to the file as an example the actual path has no .extention is more like http://doman.comindex.php/grab/check/aHR0cDovL2dvb2dsZS5jb20=/40 with no html or js extension. Can i work with this without majorly edditing the php side of things which would be a major upheaval?
Oct 13 '08 #6

Dormilich
Expert Mod 5K+
P: 8,639
send a javascript header in the returning file.
[PHP]// in php you'd write on top
header("content-type: text/javascript");[/PHP]
regards
Oct 13 '08 #7

rnd me
Expert 100+
P: 427
send a javascript header in the returning file.
[PHP]// in php you'd write on top
header("content-type: text/javascript");[/PHP]
regards
this shouldn't matter. the .src of a script tag can be any mimetype, any extention, etc.

it just has to actually be javascript to work. i serve all my .js files as HTML, which lets me view and edit them in browser. i have only seen one compatibility problem with an old version of opera in XHTML strict, but it works with recent releases.
Oct 13 '08 #8

acoder
Expert Mod 15k+
P: 16,027
That's true, though, to avoid confusion, I'd avoid the .html extension unless it's obvious that it's a js file (with proper naming).

ojsimon, give an example of generated JavaScript which doesn't work.
Oct 13 '08 #9

P: 59
i did post an example its the very first code section on my first post of this thread.

Thanks
Oct 13 '08 #10

acoder
Expert Mod 15k+
P: 16,027
Is there no chance you could add line breaks to your code using separate document.writeln() statements for each line? Though it shouldn't make much difference, you're missing <body> tags.
Oct 14 '08 #11

P: 59
Is there no chance you could add line breaks to your code using separate document.writeln() statements for each line? Though it shouldn't make much difference, you're missing <body> tags.
no it didnt make much difference but thanks, anyone else?

Thanks
Oct 14 '08 #12

acoder
Expert Mod 15k+
P: 16,027
When you load the page, are there any errors?

If possible, what you should do is only write the body content, at least for validation purposes. So, in your HTML file, have the head content in the file together with a body tag and then within the body tag load the JavaScript file:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. ...
  4. </head>
  5. <body>
  6. <script type="text/javascript" src="somefile.php"></script>
  7. </body>
  8. </html>
Oct 14 '08 #13

Post your reply

Sign in to post your reply or Sign up for a free account.