Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-17-2008, 08:09 PM   #1 (permalink)
I can't think without pen
 
Join Date: Jul 2008
Location: New York
Posts: 72
aahmed753 is on a distinguished road
Default UIWebView detect new Window, javascript open.win

when clicked on link that is supposed to open another window it UIWebView, it simply does nothing. how can i detect this so that i can simply load the requested page in the same window? is it possible at all? thanks
aahmed753 is offline   Reply With Quote
Old 08-18-2008, 05:56 PM   #2 (permalink)
I can't think without pen
 
Join Date: Jul 2008
Location: New York
Posts: 72
aahmed753 is on a distinguished road
Default

somebody? anybody? at least can someone say if this is possible at all? thanks.
aahmed753 is offline   Reply With Quote
Old 08-18-2008, 06:48 PM   #3 (permalink)
Lost in a sea of code
 
BostonMerlin's Avatar
 
Join Date: Apr 2008
Location: Boston
Posts: 399
BostonMerlin is an unknown quantity at this point
Default

I can't speak to your specific problem but if you've setup your webview to have a delegate then use this event and code to trap what a user has clicked on.. and a few more actions as well

Code:
//-uiwebview
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
	
	//CAPTURE USER LINK-CLICK.
	if (navigationType == UIWebViewNavigationTypeLinkClicked) {
		NSURL *URL = [request URL];	
		if ([[URL scheme] isEqualToString:@"http"]) {
			[[UIApplication sharedApplication] openURL: URL];
		}	 
		return NO;
	}	
	return YES;   
}
__________________
----------------------------------------------------------------------
I love being a dad, flying airplanes and writing code.
----------------------------------------------------------------------
Follow me on Twitter: @BostonMerlin
Feed your brain on Twitter: @iPhoneDev101
----------------------------------------------------------------------
iPhone Apps:
BostonMerlin is offline   Reply With Quote
Old 08-18-2008, 07:11 PM   #4 (permalink)
I can't think without pen
 
Join Date: Jul 2008
Location: New York
Posts: 72
aahmed753 is on a distinguished road
Default

links attempting to open new window will not reach this delegate method. this works for "normal" links...
aahmed753 is offline   Reply With Quote
Old 08-18-2008, 08:48 PM   #5 (permalink)
I live @ iDevKit.com
 
Join Date: Jul 2008
Posts: 142
mxweas is an unknown quantity at this point
Default

wow that code sample looks like one of my pastebins. Change the scheme to javascript instead of http. scheme is everything before the colon and javascript commands are run with javascript:window.whatever.etc.youget.the.idea

Max
mxweas is offline   Reply With Quote
Old 08-18-2008, 08:59 PM   #6 (permalink)
I can't think without pen
 
Join Date: Jul 2008
Location: New York
Posts: 72
aahmed753 is on a distinguished road
Default

guys, if link has target=_blank, then the delegate method shouldStartLoadWithRequest: does not even reach!
aahmed753 is offline   Reply With Quote
Old 01-08-2009, 09:59 AM   #7 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 2
Sadew7 is on a distinguished road
Default target = "_blank" solution

Hi

I made it work using this code:
Code:
(void)webViewDidFinishLoad:(UIWebView *)webView
{
	
	[webView stringByEvaluatingJavaScriptFromString:@"{\
					 var a = document.getElementsByTagName(\"a\"); \
					 for (var i=0; i<a.length; i++) \
					 a[i].target = \"_self\";\
					 }"];
	
}
It's a UIWebViewDelegate method implementation. Maybe not a best place, but...

It seems that there's no way to change the reference's targets, except for applying javascript.

Hope that it will help someone.
Sadew7 is offline   Reply With Quote
Old 01-19-2009, 10:03 PM   #8 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 1
jedijawa is on a distinguished road
Default

Quote:
Originally Posted by Sadew7 View Post
Hi

I made it work using this code:
Code:
(void)webViewDidFinishLoad:(UIWebView *)webView
{
	
	[webView stringByEvaluatingJavaScriptFromString:@"{\
					 var a = document.getElementsByTagName(\"a\"); \
					 for (var i=0; i<a.length; i++) \
					 a[i].target = \"_self\";\
					 }"];
	
}
It's a UIWebViewDelegate method implementation. Maybe not a best place, but...

It seems that there's no way to change the reference's targets, except for applying javascript.

Hope that it will help someone.
Clever! that absolutely helped in my case, thank you very much!
jedijawa is offline   Reply With Quote
Old 05-01-2009, 04:58 PM   #9 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 3
insomnislacker is on a distinguished road
Default Here it is including javascript:window.open() trap

Just added this to my project and it works like a charm. Hope it helps!

Code:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
	[webView stringByEvaluatingJavaScriptFromString:@"{ var a = document.getElementsByTagName(\"a\");  for (var i=0; i<a.length; i++)  { a[i].target = \"_self\"; }	 }"];
	[webView stringByEvaluatingJavaScriptFromString:@"window.open = function( inurl, blah, blah2 ) {  document.location = inurl; }"];
}
insomnislacker is offline   Reply With Quote
Old 07-17-2009, 04:57 PM   #10 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Setauket, NY
Posts: 133
hstaniloff is on a distinguished road
Question

Quote:
Originally Posted by insomnislacker View Post
Just added this to my project and it works like a charm. Hope it helps!

Code:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
	[webView stringByEvaluatingJavaScriptFromString:@"{ var a = document.getElementsByTagName(\"a\");  for (var i=0; i<a.length; i++)  { a[i].target = \"_self\"; }	 }"];
	[webView stringByEvaluatingJavaScriptFromString:@"window.open = function( inurl, blah, blah2 ) {  document.location = inurl; }"];
}
Hello;
I'm stuck on the same problem and am trying to get my code to work. I added these two lines of code to this delegate method, but no luck.
Forgive me, but what should I replace "inurl, blah, blah2" with? I don't understand.
Thanks!
hstaniloff is offline   Reply With Quote
Old 07-01-2010, 02:35 AM   #11 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 7
mahesh is on a distinguished road
Default Disable the Alert Box in UIWebView

Hi,

I am loading an External web page in the UIWebView. When the web page loads, there is an Alert Box ( with OK and Cancel buttons) with some Suggestion/ Info about the web page. I want to block this Alert Box when the web page loads in the UIWebView component in my iphone app. How can I implement in my code?

Thanks in advance.

Kind Regards,
Mahesh
mahesh is offline   Reply With Quote
Old 07-20-2010, 10:47 PM   #12 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 16
LongWeekend is on a distinguished road
Default

Quote:
Originally Posted by Sadew7 View Post
Hi

I made it work using this code:
Code:
(void)webViewDidFinishLoad:(UIWebView *)webView
{
	
	[webView stringByEvaluatingJavaScriptFromString:@"{\
					 var a = document.getElementsByTagName(\"a\"); \
					 for (var i=0; i<a.length; i++) \
					 a[i].target = \"_self\";\
					 }"];
	
}
It's a UIWebViewDelegate method implementation. Maybe not a best place, but...

It seems that there's no way to change the reference's targets, except for applying javascript.

Hope that it will help someone.
Be careful with this code. It works well on most sites but this will make Gmail and probably other javascript complex websites stop working. I'm working on / looking for a safer solution. Will let you know if and when I find it.
__________________
Check out Japanese Flash: http://japaneseflash.com
http://longweekendmobile.com
LongWeekend is offline   Reply With Quote
Old 08-08-2010, 06:48 PM   #13 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 1
marsss is on a distinguished road
Default currently selected Input field

Is there a way i can get currently selected input field in WebView document &
add special character to it in code ????

will appreciate Any suggestion
marsss is offline   Reply With Quote
Old 09-14-2010, 12:02 AM   #14 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 16
LongWeekend is on a distinguished road
Default An approach for target _blank links

I wrote a blog post on the approach I took when making Rikai Browser for iPad.

The blog post is here: Making target _blank links work in a UIWebView | Long Weekend - iPhone & iPad Apps You'll Love!

Basically similar to some suggestions earlier to use the uiwebview delegate methods.
__________________
Check out Japanese Flash: http://japaneseflash.com
http://longweekendmobile.com
LongWeekend is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 312
13 members and 299 guests
chiataytuday, coolman, givensur, glenn_sayers, guusleijsten, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:26 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0