Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-15-2005, 04:47 AM   PM User | #1
Raraken
Regular Coder

 
Join Date: Jan 2004
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Raraken is an unknown quantity at this point
JavaScript printing other <script> tags

I'm writing a website component (java based) for websites, but In internet explorer, when I use Javascript to write another <script> tag, it doesnt show up in internet explorer.

step 1: someone puts <script ... ... src="http://www.mySite.com/component.php">

step 2: (component.php's output)
document.writeln('<script ... ... src="http://www.mySite.com/runComp.php?website='+document.URL+'&blah=blah">');

step 3: (runComp.php's output)
document.writeln('<table><tr> ... ... blah blah blah ... ... </tr></table>';

I do this because alot of features requre the pages URL and such, but only javaScript has the scope to give the documents true URL. I can make the JAVA write an IFRAME, but that would be nightmarish with complications.

EDIT: this page is perfect for what I mean: http://www.webmasterworld.com/forum91/342.htm

Last edited by Raraken; 03-15-2005 at 04:52 AM..
Raraken is offline   Reply With Quote
Old 03-15-2005, 01:25 PM   PM User | #2
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
You aren't giving quite enough information. We are only interested in the page that gets sent to the user, and the actual script that doesn't work.

If the original script is embedded in the HTML page, you need to escape "</" to "<\/" inside the script element. Even less strict parsers (browsers today fall in this category) will need to escape the "</script>" sequence, however.

If the script is in a separate file, there's no need to do such catering to the HTML parsers.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 03-15-2005, 02:58 PM   PM User | #3
afru
New Coder

 
Join Date: Aug 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
afru is an unknown quantity at this point
Use the below function to load any .js file from javascript. It is DOM way of doing things.

Code:
function loadJSContent(file){
	var head = document.getElementsByTagName("head")[0];
	script = document.createElement('script');
	script.src = file;
	script.type = 'text/javascript';
	head.appendChild(script)
}
Example usage below...

Code:
loadJSContent("myexternaljavascriptfile.js");
Hope this tiny function will be of some help to you...

Have a nice day

Afru.
afru is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:36 PM.


Advertisement
Log in to turn off these ads.