Computing.Net > Forums > Web Development > Detecting browsers that don't support iframe

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Detecting browsers that don't support iframe

Reply to Message Icon

Name: RTAdams89
Date: October 18, 2009 at 23:01:12 Pacific
OS: Server 2003 SBS
CPU/Ram: 3.5GB Ram
Product: Custom / NA
Subcategory: Javascript/Ajax
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Fist (by fmwap)
Date: October 18, 2009 at 23:16:46 Pacific
Reply:

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)


0

Response Number 2
Name: RTAdams89
Date: October 18, 2009 at 23:34:49 Pacific
Reply:

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


0

Response Number 3
Name: Fist (by fmwap)
Date: October 19, 2009 at 00:01:57 Pacific
Reply:

Err, good point. Try:

search(/palm|word2|word3/)


0

Response Number 4
Name: RTAdams89
Date: October 19, 2009 at 08:01:54 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Detecting browsers that don't support iframe

!-- Causes Javascript to Ignored www.computing.net/answers/webdevel/-causes-javascript-to-ignored/691.html

Microsoft Certificate Services www.computing.net/answers/webdevel/microsoft-certificate-services/3855.html

My links don't work! www.computing.net/answers/webdevel/my-links-dont-work/2107.html