473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Script will load but not through SRC

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
12 1835
acoder
16,027 Expert Mod 8TB
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
ojsimon
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
16,027 Expert Mod 8TB
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
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
ojsimon
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
8,658 Expert Mod 8TB
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
427 Expert 256MB
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
16,027 Expert Mod 8TB
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
ojsimon
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
16,027 Expert Mod 8TB
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
ojsimon
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
16,027 Expert Mod 8TB
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

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

Similar topics

1
by: Major Man | last post by:
Hi, I run 2 websites, on 2 different domains/servers. I need a php script on server A, which when run will go to server B at (ex. http://serverB.com/images/counter.gif) and load that image 6...
0
by: pealy2 | last post by:
A quick pointer to anyone struggling with the RegisterClientScriptBlock function, unless you already have a <FORM> section in your page then the script will not be added. I use vb code to...
1
by: huyuhui | last post by:
The following is a question of LOAD utility. Question: How does the DB2 enforce table check constraints for data added to table with the LOAD utility? A. With the BUILD phase of LOAD B. With the...
3
by: jonathan184 | last post by:
Basically i am trying to make a config file which will contain to sets of paths for e.g - this file is called config.pl #!/usr/bin/perl #Path1 $sourcedir1 = '/home/test/srcdir1';
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
1
by: Mufasa | last post by:
Does anybody have any experience with a tree view control for winforms that will automatically load on demand (I could write it myself but why bother.) Just wondering which, if any of them, are...
2
by: perhapscwk | last post by:
Table below id parent_id Node 1 0 Node 1 2 0 Node 2 3 1 Node 1.1 4 1 Node 1.2 5 2 Node 2.1 write a class that will load the tree from the table using below function
2
jamwil
by: jamwil | last post by:
What's up guys. I'm having some issues... I've created a method as part of my lifestreaming class which takes an rss feed, and puts the data into a database... It's fairly simple... Check...
1
by: never2lite | last post by:
Before this evening when I came home and found an odd page showing on my desktop, my pc ran okay...not great. It is a new emachine, only purchased it in 5/2010, but there have been issues with it. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.