<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mobile browser Archives &#8212; Stampede: the strategic design &amp; technology company</title>
	<atom:link href="https://stampede-design.com/blog/tag/mobile-browser/feed/" rel="self" type="application/rss+xml" />
	<link>https://stampede-design.com/blog/tag/mobile-browser/</link>
	<description>We are creating better worlds though thoughtful design and technology. Connect with us!</description>
	<lastBuildDate>Tue, 07 Apr 2026 09:06:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.5</generator>

<image>
	<url>https://stampede-design.com/wp-content/uploads/2024/02/cropped-Stampede-Favicon-old-32x32.png</url>
	<title>mobile browser Archives &#8212; Stampede: the strategic design &amp; technology company</title>
	<link>https://stampede-design.com/blog/tag/mobile-browser/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Workaround for dropdown menu hover on mobile browsers</title>
		<link>https://stampede-design.com/blog/dropdown-menu-hover/</link>
					<comments>https://stampede-design.com/blog/dropdown-menu-hover/#comments</comments>
		
		<dc:creator><![CDATA[Shaiful Borhan]]></dc:creator>
		<pubDate>Mon, 26 Nov 2012 11:25:41 +0000</pubDate>
				<category><![CDATA[Field Notes]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[dropdown menu]]></category>
		<category><![CDATA[front-end development]]></category>
		<category><![CDATA[mobile browser]]></category>
		<category><![CDATA[tutorial]]></category>
		<guid isPermaLink="false">https://stampede-design.com/blog/?p=3039</guid>

					<description><![CDATA[<p>Shaiful is back, this time with some tips on making dropdown menu hover interaction work on mobile browsers.</p>
<p>The post <a href="https://stampede-design.com/blog/dropdown-menu-hover/">Workaround for dropdown menu hover on mobile browsers</a> appeared first on <a href="https://stampede-design.com">Stampede: the strategic design &amp; technology company</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p class="lead">In the world of web design and development, dropdown navigations or menus are a very common feature in pretty much any kinds of website because they are intuitive and not that difficult to code. However, they can be quite troublesome for users of touch-screen devices who cannot perform a proper hover interaction to expand the child panels of a dropdown navigation. </p>
<p>A simple tap (click) can be used to produce a hover effect. However, it won&#8217;t work properly on hyperlinks with URL. On some mobile browsers, hover can be emulated by a long touch on the hyperlink but this can also produce unwanted results such as opening a context menu or highlighting the text. </p>
<p>Consider this typical Suckerfish-style HTML structure:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul id=&quot;mainmenu&quot;&gt;
	&lt;li&gt;&lt;a href=&quot;about.html&quot;&gt;About&lt;/a&gt;
		&lt;ul&gt;
			&lt;li&gt;&lt;a href=&quot;about.html&quot;&gt;Overview&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href=&quot;news.html&quot;&gt;News&lt;/a&gt;
				&lt;ul&gt;
					&lt;li&gt;&lt;a href=&quot;news.html&quot;&gt;Latest&lt;/a&gt;&lt;/li&gt;
					&lt;li&gt;&lt;a href=&quot;archive.html&quot;&gt;Archive&lt;/a&gt;&lt;/li&gt;
				&lt;/ul&gt;
			&lt;/li&gt;
		&lt;/ul&gt;	
	&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p><a href="https://stampede-design.com/demo/shaiful/dropdown-mobile/" target="_blank">Here&#8217;s how it looks like.</a></p>
<p>Users using the touchscreen devices would not be able to access the sub-menus by a simple tap because both About and News has a URL that will simply redirect the page. </p>
<p>The workaround here is when a touch-screen browser is detected, we disable the URL in the hyperlinks dynamically via Javascript either by changing the location to &#8220;#&#8221; or by preventing the default action. Conveniently enough, the code for detecting touch-screen browsers can be borrowed from the awesome <a href="http://modernizr.com" target="_blank">Modernizr.js</a> library, in just three lines.</p>
<pre class="brush: jscript; title: ; notranslate">
function is_touch_device() {
  return !!('ontouchstart' in window);
}
</pre>
<p>What is left now is just to write the JS code that will go through the dropdown menu HTML and modify the &lt;a&gt; tag accordingly if it has a sub-menu. In jQuery, this can be written as follows:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() { 
	
	/* If mobile browser, prevent click on parent nav item from redirecting to URL */
	if(is_touch_device()) {	

		$('#mainmenu li &gt; ul').each(function (index, elem) {
			/* Option 1: Use this to modify the href on the &lt;a&gt; to # */
			$(elem).prev('a').attr('href' ,'#');	
			
			/* OR Option 2: Use this to keep the href on the &lt;a&gt; intact but prevent the default action */
			$(elem).prev('a').click(function(event) {
  				event.preventDefault();
			});
		});
	}
	
});
</pre>
<p>If you have a dropdown menu with only one level of children, the code can be simplified further by modifying the jQuery selector and eliminating the &#8220;each&#8221; loop.</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() { 
 
	/* If mobile browser, prevent click on parent nav item from redirecting to URL */
	if(is_touch_device()) {	
		/* Option 1: Use this to modify the href on the &lt;a&gt; to # */
		$('#mainmenu &gt; li &gt; a').attr('href' ,'#');		
		
		/* OR Option 2: Use this to keep the href on the &lt;a&gt; intact but prevent the default action */
		$('#mainmenu &gt; li &gt; a').click(function(event) {
			event.preventDefault();
		});
	}
	
});
</pre>
<p>The choice of using between Option 1 and Option 2 depends entirely on your application. If for instance you have additional JS events or interactions attached to the &lt;a&gt; tag of the dropdown menu, Option 2 might be useless because event.preventDefault(); might prevent those interactions from happening.</p>
<p><a href="https://stampede-design.com/demo/shaiful/dropdown-mobile/" target="_blank">Click here to view the demo.</a></p>
<p>As always, I am happy to hear any other methods you might have out there to make hover interaction less miserable for touch screen users. Have a nice day!</p>
<p>The post <a href="https://stampede-design.com/blog/dropdown-menu-hover/">Workaround for dropdown menu hover on mobile browsers</a> appeared first on <a href="https://stampede-design.com">Stampede: the strategic design &amp; technology company</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://stampede-design.com/blog/dropdown-menu-hover/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
	</channel>
</rss>
