Jump to content

Problem with linked .js file


Recommended Posts

Hi,BackgroundI have an HTML page that is linked to a .js file. The .js file contains a database (using an array) of reference numbers (my product numbers) and their corresponding URL links. The HTML page contains a list of "link" that send a reference number to a javascript function in the .js file that opens a window at the relevant URL. I do this because the URLs (eBay listing pages) changes for each reference number changes frequently (with each re-listing on ebay) and it's very labour-intensive to update the URLs all over my website.ProblemBecause the HTML contains photo thumbnails, it takes a short while to fully load. If the page is allowed to be fully loaded before any of the links are clicked, the scheme works. But if before the page fully loads, and I click on one of these javascripted links, the page stops loading (unloaded photo thumbnails remain blank) and the additional window with the relevant page does not open. After that, clicking on the javascripted links does nothing. The extracts of the codes are included below.Sorry for the verbose description. Hope someone can help out.ThanksCode1. HTML file is at My Webpage2. An example of the javascripted link in the HTML file:<a href="java script:gotoListing('b30020');">Garden Delight Beautiful Czech Glass Bracelet</a>3. extract of the .js file:// JavaScript Document. var ebayBaseUrl = "http://cgi.ebay.com.sg/ws/eBayISAPI.dll?ViewItem&item=";// listingUrl is the complete URL to the specific ebay page (with listing number attached).// the indexes are the prodNum without the alphabet prefix.listingUrl = new Array();listingUrl[50024] = ebayBaseUrl + "190044349595";listingUrl[80004] = ebayBaseUrl + "190044349584";listingUrl[50041] = ebayBaseUrl + "190044349577";listingUrl[30019] = ebayBaseUrl + "190044349571";listingUrl[10013] = ebayBaseUrl + "190044349563";// the list her has been truncatedfunction gotoListing(itemNum) {// extracts the 5 character number from the prodNum, removing the alphabet prefix. eg. 50023 from e50023.var extractedNum = itemNum.substring(1,6);parseInt(extractedNum);window.open(listingUrl[extractedNum],'');}

Link to post
Share on other sites

Generally, the code in an HTML document is parsed by the browser from the top down. Elements (like <div></div> or <a></a> or <img />) that are declared on, say, line 100 are parsed and added to the DOM before elements that are on, say, line 200.If you don't want the javascript to load until after the rest of the page loads, try putting the script down at the bottom of the page:

	<!-- All of your content is above here...-->	<script type="text/javascript" src="myscript.js"></script>  </body></html>

Link to post
Share on other sites

Thank you for the reply, Jesh. Actually, I would like the opposite - I'd like the javascript to load before anything else, so that the surfer can start clicking on the links if they see a picture of an item they like - even before the rest of the pictures load. At the moment, the link .js statement is in the head section, and when I transfer the javascript code to the TOP of the HTML page, the problem still occurs. In fact, I would like the page to continue loading while the new window is being opened. At present, not only does the new window not open, the HTML page stops loading. Cheers!

Generally, the code in an HTML document is parsed by the browser from the top down. Elements (like <div></div> or <a></a> or <img />) that are declared on, say, line 100 are parsed and added to the DOM before elements that are on, say, line 200.If you don't want the javascript to load until after the rest of the page loads, try putting the script down at the bottom of the page:
	<!-- All of your content is above here...-->	<script type="text/javascript" src="myscript.js"></script>  </body></html>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...