Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Quick question implementing Javascript and noscript support


travtele615

Recommended Posts

I've got a page that shows all Artists (200plus) and have a link to biography info that I want to pop up via javascript in a new window for each artist and I want to incorporate a noscript option as well.

 

my question can I move the <script lang......> tag into the actual href attribute and use "document.write" to add the "java script:popupWindow" portion to the link after php has written out all the links to the page. I had tried using document.write on the whole php echo statement but it doesn't write out the link for each artist. After the fact it dawned on me that client side code doesn't do much good when you need to write it server side first.

 

The noscript tag works as expected I just can't figure out how to get php to write out all the bio links and then have the javascript portion so that the windows will open in a popup and still have a noscript option.

 

This is the code bit I'm working with below which doesn't really contain any js at the moment other than the link but without the script tag I was getting duplicate links.

 

<script language="javascript">
<?php echo '<a href="java script:popupWindow(\'' . tep_href_link(FILENAME_POPUP_ALL_ARTISTS_INFO, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '\')">' . 'Artist Biography' . ' </a><br><br> ';?></script>
<noscript>
<?php
echo '<a href="' . tep_href_link(FILENAME_POPUP_ALL_ARTISTS_INFO, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '"' . ' target="_blank" ' . '>' . 'Artist Biography' . ' </a><br><br> ';?>
</noscript>

 

Thanks for the help

Travis

Link to comment
Share on other sites

You could try writing something like this:

 

echo '<a href="' . tep_href_link(FILENAME_POPUP_ALL_ARTISTS_INFO, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '"' . ' target="_blank" onclick="popupWindow(\'' . tep_href_link(FILENAME_POPUP_ALL_ARTISTS_INFO, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '\') return false;">' . 'Artist Biography' . ' </a>';

 

This way browsers with javascript support will use the onclick method (which returns false to stop following the link) and browsers without javascript support will just use the href attribute.

 

I haven't tested this as I am currently not on my home computer but this method should work without problems.

 

Regards,

 

*Ringo*

Link to comment
Share on other sites

Here is an example of code that uses both script and noscript for pop-up images:

 

<script language="javascript"><!--
document.write('<?php echo '<a href="java script:popupWindow(\\\'' . tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $product_info['products_id']) . '\\\')">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], addslashes($product_info['products_name']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '</a>
<a href="java script:popupWindow(\\\'' . tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $product_info['products_id']) . '\\\')">' . TEXT_CLICK_TO_ENLARGE . '</a>'; ?>');
//--></script>

<noscript>
<?php //begin three images addon
echo '<a href="' . tep_href_link(DIR_WS_IMAGES . $product_info['products_image']) . '" 
target="_blank">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], $product_info
['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '</a>
<a href="' . tep_href_link(DIR_WS_IMAGES . $product_info['products_image']) . '" target="_blank">' . 
TEXT_CLICK_TO_ENLARGE . '</a>'; ?>
</noscript>

Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Link to comment
Share on other sites

You could try writing something like this:

 

echo '<a href="' . tep_href_link(FILENAME_POPUP_ALL_ARTISTS_INFO, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '"' . ' target="_blank" onclick="popupWindow(\'' . tep_href_link(FILENAME_POPUP_ALL_ARTISTS_INFO, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '\') return false;">' . 'Artist Biography' . ' </a>';

 

for those playing along at home I needed to add a semi-colon ";" before the "return false" statement. Code below worked.

echo '<a href="' . tep_href_link(FILENAME_POPUP_ALL_ARTISTS_INFO, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '"' . ' target="_blank" onclick="popupWindow(\'' . tep_href_link(FILENAME_POPUP_ALL_ARTISTS_INFO, 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '\'); return false;">' . 'Artist Biography' . ' </a>';

 

Regards,

 

*Ringo*

 

Thansk again Ringo. Much better solution than what I was trying to cobble together.

 

Travis

Link to comment
Share on other sites

Damn those colons! ;) Just goes to show writing code on a laptop, with a screen the size of peanut, is not recommended!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...