JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Running a Script from within a Script Posted by acrinsd on 10 Mar 2009 at 3:18 PM
I am trying to use an ifelse statement to run a <script>. The problem is that when the if statement gets to the </script>, the whole thing dies.

Here is the basic code (trying to keep it as simple as possible):

</script><script language="javascript1.1">
var mlc = document.location.href;
var goodmlc = (mlc.indexOf('C:%5C') > -1);
if (goodmlc == true)
{
<script language="javascript1.1">
}
else
{
</script><script language="javascript1.1" src="http://127.0.0.1/scripts/some.js"></script>
}

The jist of the code is if the URL contains "C:\" then do nothing, otherwise run the <script>.

I have tried a number of variations, all which throw errors. I also thought about throwing this into a function and just calling the function in the ifelse, but I run into the same problem of the </script>. Any help would be greatly appreciated.
Report
Re: Running a Script from within a Script Posted by CyGuy on 12 Mar 2009 at 10:52 AM
Because of how browsers validate HTML, this is not possible. Suggest using relative path as opposed to absolute path to build your site on a local machine
Report
Re: Running a Script from within a Script Posted by acrinsd on 12 Mar 2009 at 11:25 AM
Thanks for the validation. I didn't think it was possible, but wanted to ask to make sure there wasn't something I missed.
Report
Re: Running a Script from within a Script Posted by CyGuy on 13 Mar 2009 at 12:06 AM
You may still run URL conditional code... I did a lot of that with 'buy now' buttons.

You just can't do it with HTML tags because when the browser finds the opening tag, it searches for the closing tag before executing any scripts. This behaviour is not limited to browsers as many server scripts act the same way for efficiency



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.