Welcome Guest, Not a member yet? Register   Sign In
external js file...how to link
#1

[eluser]Unknown[/eluser]
hi,where should i put my external js file and how to link it?


and i also have undefined link_tag function error.

how to solve?

thanks.
#2

[eluser]Thorpe Obazee[/eluser]
maybe you can elaborate on the problem?
#3

[eluser]Unknown[/eluser]
i use the following code in my view file

<link rel="stylesheet" href="sign.css" type="text/css" />
<script type="text/javascript" src="javascript/LoginType.js/>

but the css cannot displayed. and the js function cannot be found.

i put the css file and js file in the view folder.

it works the same if i moved the files to the root folder which is same level with the index.php.
#4

[eluser]Clooner[/eluser]
Load the url helper and then load the files in your view using <?=base_url()?>sign.css or <?=base_url()?>javascript/LoginType.js
#5

[eluser]narkaT[/eluser]
you could start you urls with a slash Smile

the url "/style.css" would cause the browser to always load "http://yourdomain.com/style.css",
regardless of how many "directory's" are in the url.

so you won't have to use the base_url() function all the time.
#6

[eluser]soupdragon[/eluser]
or as alternative / extra
i have in my controllers
$data['extraHeadContent'] = '';

which can be filled when needed so
$data['extraHeadContent'] = '<link rel="stylesheet" type="text/css" href="./css/user.css" media="screen"/>';

which then looks here
http://yourdomain.com/css/user.css

and then in your view (i have an extra header view which is always loaded)


<!-- Extra Head Content -->
<?php
if (isset($extraHeadContent)) {
if((is_array($extraHeadContent))&&(!empty($extraHeadContent))) {
foreach($extraHeadContent as $tmpnr => $toshow) {
echo $toshow."\n";

}
} else {
echo $extraHeadContent;
}
}
?>

which also means you can have as many css / jss files as needed
just if more than one
$data['extraHeadContent'][] = '<link rel="stylesheet" type="text/css" href="./css/user.css" media="screen"/>';
$data['extraHeadContent'][] = '[removed][removed]';
the line above was javascript
#7

[eluser]Colin Williams[/eluser]
Here's a good primer on the subject: http://webdesign.about.com/od/beginningt...40502a.htm
#8

[eluser]BrentNJ[/eluser]
Hi,

When I try this

$data['extraHeadContent'][] = '[removed][removed]';
$data['extraHeadContent'][] = '[removed][removed]';
print_r($data);
exit;


I get this

[extraHeadContent] => Array ( [0] => [1] => ) )


If I try just text it works.

If I just do < it works but as soon as I add &lt;script it doesn't

Any ideas?
#9

[eluser]soupdragon[/eluser]
[quote author="BrentNJ" date="1227909493"]Hi,

[extraHeadContent] => Array ( [0] => [1] => ) )
[/quote]

well you should be getting something out there ...mmmm

have you tried it with css as a test eg

Code:
data['extraHeadContent'] = '&lt;link rel="stylesheet" type="text/css" href="./css/seller.css" media="screen"/&gt;';

and for me this
Code:
$data['extraHeadContent'][] = '<xxxscript type="text/javascript" src="./js/jquery-1.2.3.min.js">[removed]
';

works no problems (obviously without the xxx but otherwise this forum eats that part




Theme © iAndrew 2016 - Forum software by © MyBB