PDA

Click to See Complete Forum and Search --> : Easy one for those who know JS


Emmanize
09-01-2006, 04:51 PM
Sorry I haven't learnt JS, so I am not too sure what the problem is. :o

I am trying to get a small pop up window via a link. I have the script for it, but I don’t want to embed it into the head of my HTML. I have linked it in the root folder but it doesn’t work. It only works when it’s embedded.

I don’t want to post my code again so I will post relevant code instead.

The code is located in a folder called javaScript, and the file is called popup.js

So I have this is my html



<div id="popup">

<script type="text/javascript" src="javascript/popup.js"></script>

</div>



(though I have a small feeling it might be something in that path that is wrong)

Maybe it’s the location of the div?



<div id= "center"><img src="images/pa*****ner2.jpg" /></div>

<div id="text-content">

<h4> Tour</h4>

<h3>Appearances</h3>

<p>blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah </p>

<a href="app_moreinfo.htm" onclick="NewWindow(this.href,'name','400','400','yes');retu rn false">View More...</a>

<div id="popup">

<script type="text/javascript" src="javascript/popup.js"></script>

</div>

</div>



Oh and keep the reply simple LOL.

EC
09-01-2006, 04:57 PM
I don't think you can do that, that looks like the code you stick in the header. I think you'll have to embed it.

peder
09-01-2006, 05:11 PM
Erm... I've baaaarely looked at JS once, and I don't remember a thing. But could it be that you've named the folder 'javaScript', and it says 'javascript' in the code? Could renaming the folder be worth a try?

Emmanize
09-01-2006, 05:18 PM
Well that’s the thing, I dunno. On my portfolio I have faded messages and that is linked, not embedded. But I am not sure if you can do it with all scripts.

resdog
09-01-2006, 06:26 PM
put the <script> tag right after your <body> tag. It could be you'er referencing the code BEFORE you link it. Also, if you're linking to the root folder, shouldn't it be "/javascript" instead of "javascript" (put a slash before the folder)? Hope that helps!

tZ
09-01-2006, 07:34 PM
you can't do that.

You can only place embedded javascript files in the header.

Something like this:


<body>
<p><a href="" onclick='popup()'>link</a></p>
</body>


Then you would need to embed the file in the head of the document.


<head>
<script type ='text/javascript' src='whatever.js'></script>
</head>


Then in your jacvascriopt file the function needes to be declared:


function popup() {
window.open()
}


Of course you would most likly need to supply arguments as well but, thats the basics behind it.

resdog
09-01-2006, 08:17 PM
You can place embedded javascript files anywhere, it's just a matter of when they "activate". If you place it in the <head> section, they won't activate until they are called, whereas they will run automatically when they load in the <body> section. Since she doesn't want the code in the <head> section, she needs to move the javascript include BEFORE the function gets called. As it is now, she is calling the function, yet the javascript file hasn't been included yet, so it wont' work. If she places the javascript include BEFORE the link, it will activate, then the javascript will recognize the function.

Conversion trackers (Google, Miva, Yahoo!) use javascript includes in the <body> tags all the time.

Emmanize
09-02-2006, 10:07 AM
Thanks resdog,



Ill try that today. I know you can link in JS files like a CSS file because it was done in my portfolio. What I am not sure about is if this includes all JS types. This one is a script that will allow a smaller window to open when the link is clicked.



I hate embedding things in the head of my HTML because it looks unorganised – but that’s just me.

Emmanize
09-02-2006, 11:18 AM
Done it!
Had to take the <script> tags out of the .js file :D

tZ
09-02-2006, 06:44 PM
yeah I know what you mean. Having everything in one place makes it look so unorganized.