I have a bit of JavaScript to open pop-up windows from an aspx file. It works if I put it directly in the script tags, but not if I try to use an external js file. I did a search on this forum for the issue already and
found an applicable thread, but the solution was a link which is apparently now broken.
Here is the how I'm refering to the file in the aspx file. This is within the header tag:
I'm not sure why the windows don't open, the Syntax is mostly correct, it could be because of popup blockers ?
Here's what I would do:
1. Add the semicolon (;) after each of the Javascript statements:
alert('Hello!');
function showCarrierList() {
window.open( "CarrierList.aspx", "Carriers",
"status = 1, width = 650, resizable = 1" );
}
2. Try changing from Double Quotes to Single Quotes (')
3. If you have FireFox open up the Javascript Console in the Tools menu - it will show you all the javascript errors on the page
4. If you are Debugging the website you will notice a tab that appears in the Solution Explorer group titled "Running Documents." Switch to this tab, and find the Javascript (should be a reference to your include file in the list.) Open it up and set a breakpoint
and see what happens when the code is hit, or maybe it doesn't even get hit.
Ah, thanks for the tip about the javascript console! That helped me sort out the problem in about 5 minutes (after spending a few hours on it yesterday. arrg!)
It turned out that for some reason that the page wasn't recognising changes that I'd made to the js file before :-?
I saved the js file as another file name and made the appropriate change to my script tag, and it worked perfectly. I also added the ;'s--I've gotten so used to VB that I forget those things lately.
Thanks a bunch!
control, alt, delete
digital hari-kiri
three-fingered salute
- Chuck Powell
Actually, I think I found the reason the browser wasn't recognising changes to my js file. I needed to clear the cashe! So I didn't really need to save under another file name . . .
Just an FYI :)
control, alt, delete
digital hari-kiri
three-fingered salute
- Chuck Powell
If I use <script language="javascript" src="file.js" type="text/javascript"> </script> it didn't work, but when i took the language and type attribute off it worked fine. I wonder why that is.
None
0 Points
123 Posts
external js and aspx files?
Jun 27, 2005 03:07 PM|mchilders|LINK
I have a bit of JavaScript to open pop-up windows from an aspx file. It works if I put it directly in the script tags, but not if I try to use an external js file. I did a search on this forum for the issue already and found an applicable thread, but the solution was a link which is apparently now broken.
Here is the how I'm refering to the file in the aspx file. This is within the header tag:
<script src="javascript.js" ></script>
Here is the text of javascript.js:
<!--
alert('hello!')
function showCarrierList() {
window.open( "CarrierList.aspx", "Carriers",
"status = 1, width = 650, resizable = 1" )
}
function viewPayments() {
window.open( "invoicePayment.aspx", "Payments",
"status = 1, width = 650, resizable = 1" )
}
function viewAccountInfo() {
window.open( "AccountList.aspx", "Accounts",
"status = 1, width = 650, resizable = 1" )
}
function forceFocus(control)
{
if (control.isfocused == "1")
control.focus();
}
alert('goodbye!')
-->
Any help is greatly appreciated!
digital hari-kiri
three-fingered salute
- Chuck Powell
All-Star
15187 Points
5768 Posts
Re: external js and aspx files?
Jun 27, 2005 04:49 PM|A1ien51|LINK
Is your JS file in the same directory as the aspx file?
Member
10 Points
92 Posts
Re: external js and aspx files?
Jun 27, 2005 04:51 PM|TylerFree|LINK
Here's what I would do:
1. Add the semicolon (;) after each of the Javascript statements:
alert('Hello!');
function showCarrierList() {
window.open( "CarrierList.aspx", "Carriers",
"status = 1, width = 650, resizable = 1" );
}
2. Try changing from Double Quotes to Single Quotes (')
3. If you have FireFox open up the Javascript Console in the Tools menu - it will show you all the javascript errors on the page
4. If you are Debugging the website you will notice a tab that appears in the Solution Explorer group titled "Running Documents." Switch to this tab, and find the Javascript (should be a reference to your include file in the list.) Open it up and set a breakpoint and see what happens when the code is hit, or maybe it doesn't even get hit.
Hope this helps.
Tyler
Member
30 Points
147 Posts
Re: external js and aspx files?
Jun 28, 2005 12:36 AM|amrinders87|LINK
Also take you <!-- and -->
None
0 Points
9 Posts
Re: external js and aspx files?
Jun 28, 2005 01:44 AM|huddy008|LINK
You may want to try adding this to your page_load in your aspx page:
Page.RegisterClientScriptBlock("MyScript", "<script language=javascript src='MyJavaScriptFile.js'>");
It worked for me [:)]
None
0 Points
123 Posts
Re: external js and aspx files?
Jun 28, 2005 08:18 AM|mchilders|LINK
It turned out that for some reason that the page wasn't recognising changes that I'd made to the js file before :-?
I saved the js file as another file name and made the appropriate change to my script tag, and it worked perfectly. I also added the ;'s--I've gotten so used to VB that I forget those things lately.
Thanks a bunch!
digital hari-kiri
three-fingered salute
- Chuck Powell
None
0 Points
123 Posts
Re: external js and aspx files?
Jun 28, 2005 08:26 AM|mchilders|LINK
Just an FYI :)
digital hari-kiri
three-fingered salute
- Chuck Powell
Member
469 Points
889 Posts
Re: external js and aspx files?
Jan 28, 2010 03:08 PM|rkeslar|LINK
If I use <script language="javascript" src="file.js" type="text/javascript"> </script> it didn't work, but when i took the language and type attribute off it worked fine. I wonder why that is.