cancel
Showing results for 
Search instead for 
Did you mean: 

window load function works slowly in safari browsers

window load function works slowly in safari browsers

Hi,

 I have write custom script to show product base image color label when page loaded in product view page by default. My script works fine in all browsers.But in safari color label shows after 4 to 5 sec of page loading.

<script type="text/javascript">
		var spConfig = new Product.Config(<?php echo $_jsonConfig ?>);
	
		/* 92 is the attribute code for color */
		if(spConfig.config.attributes[92].options.length <= 1) {
			$$('#attribute92 option')[1].selected = true;
		}
		
	 function fireEvent(element,event){
		if (document.createEventObject){
		// dispatch for IE
		var evt = document.createEventObject();
		return element.fireEvent('on'+event,evt)
		}
		else{
		// dispatch for firefox + others
		var evt = document.createEvent("HTMLEvents");
		evt.initEvent(event, true, true ); // event type,bubbling,cancelable
		return !element.dispatchEvent(evt);
		}
		}
		Event.observe(window, 'load', function() {
			
		var val = document.getElementById('product_base_image_color').value;
		var sel = document.getElementById('attribute92');
		

		for(var i = 0, j = sel.options.length; i < j; ++i) {
			if(sel.options[i].text === val) {
			   spConfig.settings[0].selectedIndex = i;
			   break;
			}
		}		
			
		//spConfig.settings[0].selectedIndex = 1;
		obj = spConfig.settings[0]; // this grabs the first select item
		Event.observe(obj,'change',function(){});
		fireEvent(obj,'change'); // this simulates selecting the first option, which triggers

		//spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
		});
 
    </script>

 Event.observe(window, 'load', function() { });

This function works slow in safari browser.Please check this and help to solve this issue.

 

 

1 REPLY 1

Re: window load function works slowly in safari browsers

Hi @devishree,

 

It seems you're using a customized JS there.

You have a reference to a custom attribute so hard to help without having the same custom code/configuration/attributes.

Maybe you can start checking that part (or removing the cutomized code to try to find where the bottleneck is)