Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: RTAdams89
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

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)

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

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

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |