Techrits Posted August 1, 2012 Share Posted August 1, 2012 Hello friends this is my first thread (and post) I just created a site and my query is that suggest me code for opening a link in new tab after the user presses button which in result navigates to another page. for better understanding please visit my site www.mysearchengine.tk there when user types a query and hit "GO" button the result must be shown in another tab (or window). Hope you got my query. Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/ Share on other sites More sharing options...
Mahngiel Posted August 1, 2012 Share Posted August 1, 2012 a href="go somewhere" target=_blank Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1365998 Share on other sites More sharing options...
hakimserwa Posted August 1, 2012 Share Posted August 1, 2012 am not sure if i got right but if you want it to be triggered by the submit button then its different otherwise its <a href="domain.com" target=_blank>keyword</a> Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1366011 Share on other sites More sharing options...
Techrits Posted August 2, 2012 Author Share Posted August 2, 2012 No this does not work because in my code I did not used a href at all... for better understanding I am putting that piece of code here case "wgoogle": if($_GET["pressed"]==1) header("Location: http://www.google.co.in/search?q={$query}"); break; as you can see I did not used html to open a link. Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1366214 Share on other sites More sharing options...
cyberRobot Posted August 2, 2012 Share Posted August 2, 2012 You could try something like this (see reply 5): http://www.sitepoint.com/forums/showthread.php?544582-Is-there-a-PHP-redirect-that-will-open-a-new-window Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1366259 Share on other sites More sharing options...
hakimserwa Posted August 2, 2012 Share Posted August 2, 2012 No this does not work because in my code I did not used a href at all... for better understanding I am putting that piece of code here case "wgoogle": if($_GET["pressed"]==1) header("Location: http://www.google.co.in/search?q={$query}"); break; as you can see I did not used html to open a link. you did not specify what you were trying to do. hopefully the above post will help. Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1366338 Share on other sites More sharing options...
Christian F. Posted August 6, 2012 Share Posted August 6, 2012 You're going about this in a bit of a roundabout way, imho. What I'd to is to open a new window first, then redirect the user with PHP (think: <a href="redir.php?id=$x" target="_blank">Sitename</a>). Much simpler to accomplish. Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367100 Share on other sites More sharing options...
pseud Posted August 6, 2012 Share Posted August 6, 2012 What you can do, is put a submit button inside an anchor tag, so assuming you're using a button, you can make it open in a new tab like this: <a href="http://link.link" target="_blank"><input type="submit" /></a> In terms of having it inside a select, you'll have to do something like this: case "wgoogle": if($_GET["pressed"]==1) echo '<script type="text/javascript">window.open("http://gumclan.org", "_blank");</script>'; break; But for me, that's opening in a new window and not a new tab. I hope I helped in some way Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367106 Share on other sites More sharing options...
Adam Posted August 6, 2012 Share Posted August 6, 2012 @pseud That's invalid mark-up; you can't have a button within an a tag. @Techrits I don't understand why you want to open results in another tab/window? That's just going to annoy the user when they can't click back. If I want pages to open in a new tab I do it manually Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367117 Share on other sites More sharing options...
pseud Posted August 6, 2012 Share Posted August 6, 2012 @pseud That's invalid mark-up; you can't have a button within an a tag. @Techrits I don't understand why you want to open results in another tab/window? That's just going to annoy the user when they can't click back. If I want pages to open in a new tab I do it manually It works though Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367120 Share on other sites More sharing options...
Adam Posted August 6, 2012 Share Posted August 6, 2012 Works != valid. Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367122 Share on other sites More sharing options...
pseud Posted August 6, 2012 Share Posted August 6, 2012 It's not like any browsers deny invalid markup, if it works then it works, surely? I guess it's an opinion, I gave a working solution but it depends on the user whether or not they're happy to use invalid markup in their document - it's unfair to call my solution invalid based on your opinion of it though. Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367126 Share on other sites More sharing options...
scootstah Posted August 6, 2012 Share Posted August 6, 2012 It's not like any browsers deny invalid markup, if it works then it works, surely? Of course they do. IE barely accepts valid markup. And even if it did work, it is an unnecessary, hacky solution. Just because it might "work" doesn't mean you should do it. That is a very bad philosophy to have as a programmer. Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367129 Share on other sites More sharing options...
Adam Posted August 6, 2012 Share Posted August 6, 2012 I didn't say your solution was invalid, I said the mark-up it produced was invalid. There's a certain amount of tolerance towards breaking standards 'to get the job done', but the reason the OP is having difficulty doing what he wants to do is because you're not meant to do it. That's why throwing together hacky code to get it working is frowned on. There's a reason for standards.. Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367130 Share on other sites More sharing options...
redarrow Posted August 6, 2012 Share Posted August 6, 2012 Also think about the seo of the page, it all needs to be validated. if a spider hit a incorrect formatted html xhtml page then the spider spits a error then your page is put lower in the spider it self(that the theory any way.) Just looked at your website, and the way your scrapping other spiders well slow why? Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367135 Share on other sites More sharing options...
pseud Posted August 6, 2012 Share Posted August 6, 2012 You looked at my website? What's wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367153 Share on other sites More sharing options...
scootstah Posted August 6, 2012 Share Posted August 6, 2012 You looked at my website? What's wrong with it? I think he was talking to Techrits... Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367155 Share on other sites More sharing options...
pseud Posted August 6, 2012 Share Posted August 6, 2012 Oh right, I was gonna say - my site is SMF and only has a few custom pages. I apologise for my bad information by the way. I'm new to this scene, ill not say stuff unless I'm totally sure now. I don't wanna be that forum guy who pretends to know everything haha x Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367157 Share on other sites More sharing options...
redarrow Posted August 6, 2012 Share Posted August 6, 2012 i was thank you scootstah Techrits not your web site. scootstah grate programmer and you seem to no the theory so well,i would love to how to do programming so well as you, thanks for helping us all. i guess it takes practice and loads of it to be any good at php mysql sorry i am a bad speller and writer Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1367158 Share on other sites More sharing options...
Techrits Posted August 15, 2012 Author Share Posted August 15, 2012 @pseud That's invalid mark-up; you can't have a button within an a tag. @Techrits I don't understand why you want to open results in another tab/window? That's just going to annoy the user when they can't click back. If I want pages to open in a new tab I do it manually Thank to all for your reply. Sorry for late reply actually my problem was solved and hence I never looked at this thread. @Adam Just visit mysearchengine.tk once and then you will understand why I'm doing this coz there you can't open in new tab manually. Quote Link to comment https://forums.phpfreaks.com/topic/266548-how-to-open-page-in-new-tab/#findComment-1369526 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.