Detecting browsers that don't support iframe

Custom / NA
October 18, 2009 at 23:01:12
Specs: Server 2003 SBS, 3.5GB Ram
I'm trying to apply a JavaScript function only to browsers that support iframes. Currently, I am working with this:

function into_frame()
{
var uagent = navigator.userAgent.toLowerCase();
if (uagent.search("palm") == -1)
{
if (top.location == location)
{
var str1, str2;
str1 = location.href;
str2 = str1.replace ("&", "andandand");
top.location.href = "http://asurfc.com/forum.php?iframe=" + str2;
}
}
}

In this case, I don't run the JavaScript when the user agent indicates the site is open on a Palm device (which doesn't support iframes). I would like to check for other words in the useragent string and thought I could do that by using

search("palm"|"word2"|"word3")

but this doesn't work. How would I go about checkign if any of many possible words are in the useragent string?

-Ryan Adams

Free Computer Tips and more:http://RyanTAdams.com
Paid Tech Support: Black Diamond


See More: Detecting browsers that dont support iframe

Report •


#1
October 18, 2009 at 23:16:46
Create an array of blocked user agents and then loop through & it test each against the user agent?

something like:

var no_iframe_ua = new Array('palm','word1','word2');
var iframe_support = true;
var uagent = navigator.userAgent.toLowerCase();
for (c=0; c<= (no_iframe_ua.length -1); c++) {
if (uagent.search(no_iframe_ua[c]) != -1) {
iframe_support = false;
break;
}
}

if (iframe_support == true) {
//IFrame code
} else {
//No iframe code
}


(I didn't test this code - could be a syntax error in there somewhere)


Report •

#2
October 18, 2009 at 23:34:49
I suppose that would work. Why doesn't using the | character between words in the search() function work though?

-Ryan Adams

Free Computer Tips and more:http://RyanTAdams.com
Paid Tech Support: Black Diamond


Report •

#3
October 19, 2009 at 00:01:57
Err, good point. Try:

search(/palm|word2|word3/)


Report •

Related Solutions

#4
October 19, 2009 at 08:01:54
I ended up using

if (uagent.search(/"palm"|"windows ce"|"winmobile"/) == -1)

which seems to work. Looks like it needs the forward slashes and quotes.

-Ryan Adams

Free Computer Tips and more:http://RyanTAdams.com
Paid Tech Support: Black Diamond


Report •


Ask Question