Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening URL in browser by clicking button

Hi friends,
I am getting data from server when user post a link on his timeline am displaying like this but my requirement is when i click Title then it will open browser. How can i do this?

when i click **Bollywood.com:Entertainment news,movie,music and fashion rev**

like image 284
Sravan Goud Avatar asked May 15 '14 09:05

Sravan Goud


People also ask

How do I turn a button into a link?

Adding styles as button to a link: This method create a simple anchor tag link and then apply some CSS property to makes it like a button. Using form tags: This method uses form tag and button tag. When button is clicked then the form action attribute is called and web page redirect into the given location.

How do I open a URL in the same window or a tab?

The JavaScript window. open() method allows you to open URL in the browser tab or window. You can use _self value in the second parameter of the window. open() method to open URL in the same tab and in the same window with JavaScript.

How do you make a link open in a new tab HTML?

You can make a HTML link open in a new tab by adding the target=”_blank” attribute. You should insert this after the link address.


1 Answers

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]];

Will open a URL by the Application defined for the scheme. http has Safari as default (I guess)

To open it in the App itself create a ViewController + xib, add a UIWebView to your View & Buttons to get back to the app.

Then you can create an instance of your new ViewController and present it with

[self presentViewController:WebVC animated:YES completion:^(void){
    [[WebVC MyWebView] loadRequest: [NSMutableURLRequest requestWithURL:[NSURL URLWithString: @"http://stackoverflow.com"]];
}];

e.g.

To make it even easier you could add a function to your ViewController like this one

-(void) LoadUrlFromString: (NSString *)url{
[self.MyWebView loadRequest: [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url]]];
}

and then just do as before but call

[WebVC LoadUrlFromString:@"http://stackoverflow.com"]; 

on completition

like image 187
user3567992 Avatar answered Oct 21 '22 22:10

user3567992